Skip to content

Commit

Permalink
Test all constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Aug 27, 2020
1 parent 3535c17 commit 9ac33a1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,46 @@ public void testCodec200() {
assertNotNull(codec);
}

@Test
public void testConstructors() {
Base32 base32;
base32 = new Base32();
base32 = new Base32(-1);
base32 = new Base32(-1, new byte[] {});
base32 = new Base32(32, new byte[] {});
base32 = new Base32(32, new byte[] {}, false);
// This is different behaviour than Base64 which validates the separator
// even when line length is negative.
base32 = new Base32(-1, new byte[] { 'A' });
try {
base32 = new Base32(32, null);
fail("Should have rejected null line separator");
} catch (final IllegalArgumentException ignored) {
// Expected
}
try {
base32 = new Base32(32, new byte[] { 'A' });
fail("Should have rejected attempt to use 'A' as a line separator");
} catch (final IllegalArgumentException ignored) {
// Expected
}
try {
base32 = new Base32(32, new byte[] { '=' });
fail("Should have rejected attempt to use '=' as a line separator");
} catch (final IllegalArgumentException ignored) {
// Expected
}
base32 = new Base32(32, new byte[] { '$' }); // OK
try {
base32 = new Base32(32, new byte[] { 'A', '$' });
fail("Should have rejected attempt to use 'A$' as a line separator");
} catch (final IllegalArgumentException ignored) {
// Expected
}
base32 = new Base32(32, new byte[] { ' ', '$', '\n', '\r', '\t' }); // OK
assertNotNull(base32);
}

/**
* Test encode and decode of empty byte array.
*/
Expand Down

0 comments on commit 9ac33a1

Please sign in to comment.