From 9ac33a12a500bbc3ea40685aac61c95169443957 Mon Sep 17 00:00:00 2001 From: Alex Herbert Date: Thu, 27 Aug 2020 23:49:41 +0100 Subject: [PATCH] Test all constructors --- .../commons/codec/binary/Base32Test.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java b/src/test/java/org/apache/commons/codec/binary/Base32Test.java index 41ee7094ea..9e25bd5ce8 100644 --- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java +++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java @@ -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. */