113: moar tests

This commit is contained in:
Les Hazlewood 2016-04-12 18:56:48 -07:00
parent 716c6fd500
commit 3bcd7632cd
2 changed files with 29 additions and 1 deletions

View File

@ -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;

View File

@ -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)
}
}