Skip to content

Commit 9ac33a1

Browse files
committed
Test all constructors
1 parent 3535c17 commit 9ac33a1

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/binary/Base32Test.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,46 @@ public void testCodec200() {
240240
assertNotNull(codec);
241241
}
242242

243+
@Test
244+
public void testConstructors() {
245+
Base32 base32;
246+
base32 = new Base32();
247+
base32 = new Base32(-1);
248+
base32 = new Base32(-1, new byte[] {});
249+
base32 = new Base32(32, new byte[] {});
250+
base32 = new Base32(32, new byte[] {}, false);
251+
// This is different behaviour than Base64 which validates the separator
252+
// even when line length is negative.
253+
base32 = new Base32(-1, new byte[] { 'A' });
254+
try {
255+
base32 = new Base32(32, null);
256+
fail("Should have rejected null line separator");
257+
} catch (final IllegalArgumentException ignored) {
258+
// Expected
259+
}
260+
try {
261+
base32 = new Base32(32, new byte[] { 'A' });
262+
fail("Should have rejected attempt to use 'A' as a line separator");
263+
} catch (final IllegalArgumentException ignored) {
264+
// Expected
265+
}
266+
try {
267+
base32 = new Base32(32, new byte[] { '=' });
268+
fail("Should have rejected attempt to use '=' as a line separator");
269+
} catch (final IllegalArgumentException ignored) {
270+
// Expected
271+
}
272+
base32 = new Base32(32, new byte[] { '$' }); // OK
273+
try {
274+
base32 = new Base32(32, new byte[] { 'A', '$' });
275+
fail("Should have rejected attempt to use 'A$' as a line separator");
276+
} catch (final IllegalArgumentException ignored) {
277+
// Expected
278+
}
279+
base32 = new Base32(32, new byte[] { ' ', '$', '\n', '\r', '\t' }); // OK
280+
assertNotNull(base32);
281+
}
282+
243283
/**
244284
* Test encode and decode of empty byte array.
245285
*/

0 commit comments

Comments
 (0)