From 3bcd7632cd3bdae119c91adbbaa3b718626343d6 Mon Sep 17 00:00:00 2001 From: Les Hazlewood Date: Tue, 12 Apr 2016 18:56:48 -0700 Subject: [PATCH] 113: moar tests --- .../java/io/jsonwebtoken/lang/Arrays.java | 6 ++++- .../io/jsonwebtoken/lang/ArraysTest.groovy | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/io/jsonwebtoken/lang/ArraysTest.groovy 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) + } +}