1+ package at .favre .lib .bytes ;
2+
3+ import org .junit .Test ;
4+
5+ import java .nio .ByteOrder ;
6+
7+ import static org .junit .Assert .assertEquals ;
8+ import static org .junit .Assert .assertNotEquals ;
9+
10+ public class BinaryToTextEncodingTest {
11+ @ Test
12+ public void encodeHex () throws Exception {
13+ assertEquals ("010203" , new BinaryToTextEncoding .Hex (false ).encode (new byte []{1 , 2 , 3 }, ByteOrder .BIG_ENDIAN ));
14+ assertEquals ("030201" , new BinaryToTextEncoding .Hex (false ).encode (new byte []{1 , 2 , 3 }, ByteOrder .LITTLE_ENDIAN ));
15+ assertNotEquals (new BinaryToTextEncoding .Hex (false ).encode (new byte []{1 , 2 , 3 }, ByteOrder .LITTLE_ENDIAN ), new BinaryToTextEncoding .Hex (false ).encode (new byte []{1 , 2 , 3 }, ByteOrder .BIG_ENDIAN ));
16+ }
17+
18+ @ Test
19+ public void encodeBaseRadix () throws Exception {
20+ assertEquals ("100211" , new BinaryToTextEncoding .BaseRadix (16 ).encode (new byte []{16 , 2 , 17 }, ByteOrder .BIG_ENDIAN ));
21+ assertEquals ("110210" , new BinaryToTextEncoding .BaseRadix (16 ).encode (new byte []{16 , 2 , 17 }, ByteOrder .LITTLE_ENDIAN ));
22+ assertNotEquals (new BinaryToTextEncoding .BaseRadix (2 ).encode (new byte []{1 , 2 , 3 }, ByteOrder .LITTLE_ENDIAN ), new BinaryToTextEncoding .BaseRadix (2 ).encode (new byte []{1 , 2 , 3 }, ByteOrder .BIG_ENDIAN ));
23+
24+ }
25+
26+ @ Test
27+ public void encodeBase64 () throws Exception {
28+ assertEquals ("EAIR" , new BinaryToTextEncoding .Base64Encoding ().encode (new byte []{16 , 2 , 17 }, ByteOrder .BIG_ENDIAN ));
29+ assertEquals ("EQIQ" , new BinaryToTextEncoding .Base64Encoding ().encode (new byte []{17 , 2 , 16 }, ByteOrder .BIG_ENDIAN ));
30+ assertEquals ("EQIQ" , new BinaryToTextEncoding .Base64Encoding ().encode (new byte []{16 , 2 , 17 }, ByteOrder .LITTLE_ENDIAN ));
31+ assertNotEquals (new BinaryToTextEncoding .Base64Encoding ().encode (new byte []{1 , 2 , 3 }, ByteOrder .LITTLE_ENDIAN ), new BinaryToTextEncoding .Base64Encoding ().encode (new byte []{1 , 2 , 3 }, ByteOrder .BIG_ENDIAN ));
32+ }
33+ }
0 commit comments