@Test(expected = UnsupportedCharsetException.class) public void testCustomCharsetBadName() { new Hex(BAD_ENCODING_NAME); }
@Test public void testEncodeHexByteBufferEmpty() { assertTrue(Arrays.equals(new char[0], Hex.encodeHex(ByteBuffer.allocate(0)))); assertTrue(Arrays.equals(new byte[0], new Hex().encode(ByteBuffer.allocate(0)))); }
@Test public void testDecodeByteBufferOddCharacters() { final ByteBuffer buffer = ByteBuffer.allocate(1); buffer.put((byte) 65); try { new Hex().decode(buffer); fail("An exception wasn't thrown when trying to decode an odd number of characters"); } catch (final DecoderException e) { // Expected exception } }
@Test public void testEncodeByteBufferEmpty() { assertTrue(Arrays.equals(new byte[0], new Hex().encode(ByteBuffer.allocate(0)))); }
@Test public void testEncodeByteBufferObjectEmpty() throws EncoderException { assertTrue(Arrays.equals(new char[0], (char[]) new Hex().encode((Object) ByteBuffer.allocate(0)))); }
@Test public void testEncodeHexByteArrayEmpty() { assertTrue(Arrays.equals(new char[0], Hex.encodeHex(new byte[0]))); assertTrue(Arrays.equals(new byte[0], new Hex().encode(new byte[0]))); }
@Test public void testCustomCharsetToString() { assertTrue(new Hex().toString().indexOf(Hex.DEFAULT_CHARSET_NAME) >= 0); }
@Test public void testEncodeByteArrayEmpty() { assertTrue(Arrays.equals(new byte[0], new Hex().encode(new byte[0]))); }
@Test public void testEncodeByteArrayObjectEmpty() throws EncoderException { assertTrue(Arrays.equals(new char[0], (char[]) new Hex().encode((Object) new byte[0]))); }
@Test public void testDecodeByteArrayObjectEmpty() throws DecoderException { assertTrue(Arrays.equals(new byte[0], (byte[]) new Hex().decode((Object) new byte[0]))); }
@Test public void testDecodeStringEmpty() throws DecoderException { assertTrue(Arrays.equals(new byte[0], (byte[]) new Hex().decode(""))); }
@Test public void testGetCharsetName() { Assert.assertEquals(Charsets.UTF_8.name(), new Hex(Charsets.UTF_8).getCharsetName()); }
@Test public void testEncodeStringEmpty() throws EncoderException { assertTrue(Arrays.equals(new char[0], (char[]) new Hex().encode(""))); }
@Test public void testDecodeBadCharacterPos1() { try { new Hex().decode("0q"); fail("An exception wasn't thrown when trying to decode an illegal character"); } catch (final DecoderException e) { // Expected exception } }
@Test public void testDecodeBadCharacterPos0() { try { new Hex().decode("q0"); fail("An exception wasn't thrown when trying to decode an illegal character"); } catch (final DecoderException e) { // Expected exception } }
@Test public void testEncodeClassCastException() { try { new Hex().encode(new int[] { 65 }); fail("An exception wasn't thrown when trying to encode."); } catch (final EncoderException e) { // Expected exception } }
@Test public void testDecodeClassCastException() { try { new Hex().decode(new int[] { 65 }); fail("An exception wasn't thrown when trying to decode."); } catch (final DecoderException e) { // Expected exception } }
@Test public void testDecodeHexStringOddCharacters() { try { new Hex().decode("6"); fail("An exception wasn't thrown when trying to decode an odd number of characters"); } catch (final DecoderException e) { // Expected exception } }
@Test public void testDecodeByteArrayOddCharacters() { try { new Hex().decode(new byte[] { 65 }); fail("An exception wasn't thrown when trying to decode an odd number of characters"); } catch (final DecoderException e) { // Expected exception } }
@Test public void testGetCharset() { Assert.assertEquals(Charsets.UTF_8, new Hex(Charsets.UTF_8).getCharset()); }