Skip to content

Commit

Permalink
Add more fail tests in encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfav committed Nov 22, 2017
1 parent b6864a4 commit c0f3359
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/java/at/favre/lib/bytes/BinaryToTextEncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ public void encodeBaseRadix() throws Exception {
assertEquals("100211", new BinaryToTextEncoding.BaseRadix(16).encode(new byte[]{16, 2, 17}, ByteOrder.BIG_ENDIAN));
assertEquals("110210", new BinaryToTextEncoding.BaseRadix(16).encode(new byte[]{16, 2, 17}, ByteOrder.LITTLE_ENDIAN));
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));
}

@Test(expected = IllegalArgumentException.class)
public void decodeInvalidRadix116() throws Exception {
new BinaryToTextEncoding.BaseRadix(16).decode("AAI=");
}

@Test(expected = IllegalArgumentException.class)
public void decodeInvalidRadix36() throws Exception {
new BinaryToTextEncoding.BaseRadix(36).decode("AAI=");
}

@Test
Expand All @@ -56,4 +65,14 @@ public void encodeBase64() throws Exception {
assertEquals("EQIQ", new BinaryToTextEncoding.Base64Encoding().encode(new byte[]{16, 2, 17}, ByteOrder.LITTLE_ENDIAN));
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));
}

@Test(expected = IllegalArgumentException.class)
public void decodeInvalidBase64() throws Exception {
new BinaryToTextEncoding.Base64Encoding().decode("(&´´");
}

@Test(expected = IllegalArgumentException.class)
public void decodeHalfInvalidBase64() throws Exception {
new BinaryToTextEncoding.Base64Encoding().decode("EAI`");
}
}

0 comments on commit c0f3359

Please sign in to comment.