Skip to content

Commit e5824b5

Browse files
committed
Add some more fail tests
1 parent f09db4d commit e5824b5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/at/favre/lib/bytes/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static byte[] decode(String in) {
7474
} else if (c == '\n' || c == '\r' || c == ' ' || c == '\t') {
7575
continue;
7676
} else {
77-
return null;
77+
throw new IllegalArgumentException("invalid character to decode: " + c);
7878
}
7979

8080
// Append this char's 6 bits to the word.

src/test/java/at/favre/lib/bytes/BytesParseAndEncodingTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public void parseHex() throws Exception {
4444
assertArrayEquals(defaultArray, Bytes.parseHex(Bytes.parseHex("A0E1").encodeHex()).array());
4545
}
4646

47+
@Test(expected = IllegalArgumentException.class)
48+
public void parseHexInvalid() throws Exception {
49+
Bytes.parseHex("A0E");
50+
}
51+
4752
@Test
4853
public void encodeHex() throws Exception {
4954
byte[] defaultArray = new byte[]{(byte) 0xA0, (byte) 0xE1};
@@ -58,6 +63,11 @@ public void parseBase64() throws Exception {
5863
assertArrayEquals(encodingExample, Bytes.parseBase64("SpT9/x6v7Q==").array());
5964
}
6065

66+
@Test(expected = IllegalArgumentException.class)
67+
public void parseBase64Invalid() throws Exception {
68+
Bytes.parseBase64("☕");
69+
}
70+
6171
@Test
6272
public void encodeBase64() throws Exception {
6373
assertEquals("SpT9/x6v7Q==", Bytes.from(encodingExample).encodeBase64());

0 commit comments

Comments
 (0)