commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-codec] 06/08: Test all constructors
Date Thu, 27 Aug 2020 23:19:06 GMT
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 9ac33a12a500bbc3ea40685aac61c95169443957
Author: Alex Herbert <aherbert@apache.org>
AuthorDate: Thu Aug 27 23:49:41 2020 +0100

    Test all constructors
---
 .../apache/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 41ee709..9e25bd5 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 class Base32Test {
         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.
      */


Mime
View raw message