diff --git a/src/main/java/io/jsonwebtoken/lang/Arrays.java b/src/main/java/io/jsonwebtoken/lang/Arrays.java index b19d491c..09ea730a 100644 --- a/src/main/java/io/jsonwebtoken/lang/Arrays.java +++ b/src/main/java/io/jsonwebtoken/lang/Arrays.java @@ -3,7 +3,11 @@ package io.jsonwebtoken.lang; /** * @since 0.6 */ -public abstract class Arrays { +public final class Arrays { + + private static final Arrays INSTANCE = new Arrays(); + + private Arrays(){} public static int length(byte[] bytes) { return bytes != null ? bytes.length : 0; diff --git a/src/test/groovy/io/jsonwebtoken/lang/ArraysTest.groovy b/src/test/groovy/io/jsonwebtoken/lang/ArraysTest.groovy new file mode 100644 index 00000000..b95fde43 --- /dev/null +++ b/src/test/groovy/io/jsonwebtoken/lang/ArraysTest.groovy @@ -0,0 +1,24 @@ +package io.jsonwebtoken.lang + +import groovy.json.internal.Charsets +import org.junit.Test +import static org.junit.Assert.* + +class ArraysTest { + + @Test + void testByteArrayLengthWithNull() { + assertEquals 0, Arrays.length(null) + } + + @Test + void testByteArrayLengthWithEmpty() { + assertEquals 0, Arrays.length(new byte[0]) + } + + @Test + void testByteArrayLengthWithElements() { + byte[] bytes = "hello".getBytes(Charsets.UTF_8) + assertEquals 5, Arrays.length(bytes) + } +}