@@ -540,6 +540,9 @@ void testEncodeObjectNull() throws Exception {
540540 void testFromAsciiByteArray () {
541541 assertEquals (0 , BinaryCodec .fromAscii ((byte []) null ).length );
542542 assertEquals (0 , BinaryCodec .fromAscii (new byte [0 ]).length );
543+ assertArrayEquals (new byte [0 ], BinaryCodec .fromAscii ("1" .getBytes (CHARSET_UTF8 )));
544+ assertArrayEquals (new byte [] { 0 }, BinaryCodec .fromAscii ("100000000" .getBytes (CHARSET_UTF8 )));
545+ assertArrayEquals (new byte [] { (byte ) 0x80 }, BinaryCodec .fromAscii ("010000000" .getBytes (CHARSET_UTF8 )));
543546 // With a single raw binary
544547 byte [] bits = new byte [1 ];
545548 byte [] decoded = BinaryCodec .fromAscii ("00000000" .getBytes (CHARSET_UTF8 ));
@@ -631,6 +634,9 @@ void testFromAsciiByteArray() {
631634 void testFromAsciiCharArray () {
632635 assertEquals (0 , BinaryCodec .fromAscii ((char []) null ).length );
633636 assertEquals (0 , BinaryCodec .fromAscii (new char [0 ]).length );
637+ assertArrayEquals (new byte [0 ], BinaryCodec .fromAscii ("1" .toCharArray ()));
638+ assertArrayEquals (new byte [] { 0 }, BinaryCodec .fromAscii ("100000000" .toCharArray ()));
639+ assertArrayEquals (new byte [] { (byte ) 0x80 }, BinaryCodec .fromAscii ("010000000" .toCharArray ()));
634640 // With a single raw binary
635641 byte [] bits = new byte [1 ];
636642 byte [] decoded = BinaryCodec .fromAscii ("00000000" .toCharArray ());
@@ -1069,6 +1075,7 @@ void testToAsciiString() {
10691075 bits [1 ] = (byte ) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7 );
10701076 encoded = BinaryCodec .toAsciiString (bits );
10711077 assertEquals ("1111111111111111" , encoded );
1078+ assertEquals ("" , BinaryCodec .toAsciiString (null ));
10721079 }
10731080
10741081 /**
@@ -1160,30 +1167,4 @@ void testToByteArrayFromString() {
11601167 assertEquals (0 , instance .toByteArray ((String ) null ).length );
11611168 }
11621169
1163- @ Test
1164- void testFromAsciiByteArrayLengthLessThan8ReturnsEmpty () {
1165- assertArrayEquals (new byte [0 ], BinaryCodec .fromAscii ("1" .getBytes (CHARSET_UTF8 )));
1166- }
1167-
1168- @ Test
1169- void testFromAsciiCharArrayLengthLessThan8ReturnsEmpty () {
1170- assertArrayEquals (new byte [0 ], BinaryCodec .fromAscii ("1" .toCharArray ()));
1171- }
1172-
1173- @ Test
1174- void testFromAsciiByteArrayLengthNotMultipleOf8IgnoresLeadingBits () {
1175- assertArrayEquals (new byte [] { 0 }, BinaryCodec .fromAscii ("100000000" .getBytes (CHARSET_UTF8 )));
1176- assertArrayEquals (new byte [] { (byte ) 0x80 }, BinaryCodec .fromAscii ("010000000" .getBytes (CHARSET_UTF8 )));
1177- }
1178-
1179- @ Test
1180- void testFromAsciiCharArrayLengthNotMultipleOf8IgnoresLeadingBits () {
1181- assertArrayEquals (new byte [] { 0 }, BinaryCodec .fromAscii ("100000000" .toCharArray ()));
1182- assertArrayEquals (new byte [] { (byte ) 0x80 }, BinaryCodec .fromAscii ("010000000" .toCharArray ()));
1183- }
1184-
1185- @ Test
1186- void testToAsciiStringNullReturnsEmptyString () {
1187- assertEquals ("" , BinaryCodec .toAsciiString (null ));
1188- }
11891170}
0 commit comments