From 66b30e2e106ec45e53eb5fb5a7381939982ae1ab Mon Sep 17 00:00:00 2001 From: Les Hazlewood Date: Fri, 8 May 2015 20:22:22 -0700 Subject: [PATCH] #18: extracted Android-specific logic out of the Base64Codec to its own class. Created a factory that can return either depending on environment. Ensured all code other than the lang package is at 100% test coverage. --- pom.xml | 47 +++++++----- .../jsonwebtoken/impl/AndroidBase64Codec.java | 30 ++++++++ .../io/jsonwebtoken/impl/Base64Codec.java | 33 --------- .../impl/DefaultTextCodecFactory.java | 51 +++++++++++++ .../java/io/jsonwebtoken/impl/TextCodec.java | 2 +- .../jsonwebtoken/impl/TextCodecFactory.java | 21 ++++++ .../ExpiredJwtExceptionTest.groovy | 5 +- .../jsonwebtoken/JwtHandlerAdapterTest.groovy | 5 +- .../io/jsonwebtoken/JwtParserTest.groovy | 7 +- .../groovy/io/jsonwebtoken/JwtsTest.groovy | 28 ++++---- .../PrematureJwtExceptionTest.groovy | 5 +- .../SignatureAlgorithmTest.groovy | 7 +- .../impl/AndroidBase64CodecTest.groovy | 72 +++++++++++++++++++ .../impl/DefaultHeaderTest.groovy | 4 +- .../impl/DefaultJwsHeaderTest.groovy | 4 +- .../jsonwebtoken/impl/DefaultJwsTest.groovy | 4 +- .../impl/DefaultJwtBuilderTest.groovy | 4 +- .../impl/DefaultTextCodecFactoryTest.groovy | 68 ++++++++++++++++++ .../io/jsonwebtoken/impl/JwtMapTest.groovy | 7 +- ...efaultSignatureValidatorFactoryTest.groovy | 4 +- .../crypto/DefaultSignerFactoryTest.groovy | 7 +- .../crypto/EllipticCurveProviderTest.groovy | 5 +- ...EllipticCurveSignatureValidatorTest.groovy | 4 +- .../crypto/EllipticCurveSignerTest.groovy | 4 +- .../impl/crypto/MacProviderTest.groovy | 6 +- .../impl/crypto/MacSignerTest.groovy | 4 +- .../impl/crypto/RsaProviderTest.groovy | 4 +- .../crypto/RsaSignatureValidatorTest.groovy | 7 +- .../impl/crypto/RsaSignerTest.groovy | 4 +- .../impl/crypto/SignatureProviderTest.groovy | 4 +- 30 files changed, 330 insertions(+), 127 deletions(-) create mode 100644 src/main/java/io/jsonwebtoken/impl/AndroidBase64Codec.java create mode 100644 src/main/java/io/jsonwebtoken/impl/DefaultTextCodecFactory.java create mode 100644 src/main/java/io/jsonwebtoken/impl/TextCodecFactory.java create mode 100644 src/test/groovy/io/jsonwebtoken/impl/AndroidBase64CodecTest.groovy create mode 100644 src/test/groovy/io/jsonwebtoken/impl/DefaultTextCodecFactoryTest.groovy diff --git a/pom.xml b/pom.xml index 5e4c7574..55919070 100644 --- a/pom.xml +++ b/pom.xml @@ -70,8 +70,9 @@ 2.3.0-beta-2 1.0.7 - 3.1 - 6.8 + 3.3.1 + 4.12 + 1.6.2 2.12.4 @@ -83,14 +84,6 @@ slf4j-api ${slf4j.version} - com.fasterxml.jackson.core jackson-databind @@ -107,8 +100,8 @@ + This dependency is only a stub of the actual implementation, which means we can't use it at test time. + An Android environment is required to test for real. --> com.google.android android @@ -129,12 +122,6 @@ ${logback.version} test - - org.testng - testng - ${testng.version} - test - org.codehaus.groovy groovy-all @@ -147,6 +134,30 @@ ${easymock.version} test + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-easymock + ${powermock.version} + test + + + org.powermock + powermock-core + ${powermock.version} + test + + + junit + junit + 4.12 + test + diff --git a/src/main/java/io/jsonwebtoken/impl/AndroidBase64Codec.java b/src/main/java/io/jsonwebtoken/impl/AndroidBase64Codec.java new file mode 100644 index 00000000..8ad32c87 --- /dev/null +++ b/src/main/java/io/jsonwebtoken/impl/AndroidBase64Codec.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.jsonwebtoken.impl; + +public class AndroidBase64Codec extends AbstractTextCodec { + + @Override + public String encode(byte[] data) { + int flags = android.util.Base64.NO_PADDING | android.util.Base64.NO_WRAP; + return android.util.Base64.encodeToString(data, flags); + } + + @Override + public byte[] decode(String encoded) { + return android.util.Base64.decode(encoded, android.util.Base64.DEFAULT); + } +} diff --git a/src/main/java/io/jsonwebtoken/impl/Base64Codec.java b/src/main/java/io/jsonwebtoken/impl/Base64Codec.java index 16a98cbf..d2faf5c0 100644 --- a/src/main/java/io/jsonwebtoken/impl/Base64Codec.java +++ b/src/main/java/io/jsonwebtoken/impl/Base64Codec.java @@ -17,45 +17,12 @@ package io.jsonwebtoken.impl; public class Base64Codec extends AbstractTextCodec { - private static final boolean ANDROID = isAndroid(); - - private static boolean isAndroid() { - - String name = System.getProperty("java.vm.name"); - if (name != null) { - String lcase = name.toLowerCase(); - return lcase.contains("dalvik"); - } - - name = System.getProperty("java.vm.vendor"); - if (name != null) { - String lcase = name.toLowerCase(); - return lcase.contains("android"); - } - - return false; - } - public String encode(byte[] data) { - - if (ANDROID) { - int flags = android.util.Base64.NO_PADDING | android.util.Base64.NO_WRAP; - return android.util.Base64.encodeToString(data, flags); - } - - //else, assume standard JVM return javax.xml.bind.DatatypeConverter.printBase64Binary(data); } @Override public byte[] decode(String encoded) { - - if (ANDROID) { - return android.util.Base64.decode(encoded, android.util.Base64.DEFAULT); - } - - //else assume standard JVM: return javax.xml.bind.DatatypeConverter.parseBase64Binary(encoded); } - } diff --git a/src/main/java/io/jsonwebtoken/impl/DefaultTextCodecFactory.java b/src/main/java/io/jsonwebtoken/impl/DefaultTextCodecFactory.java new file mode 100644 index 00000000..9b3d9f6f --- /dev/null +++ b/src/main/java/io/jsonwebtoken/impl/DefaultTextCodecFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.jsonwebtoken.impl; + +public class DefaultTextCodecFactory implements TextCodecFactory { + + protected String getSystemProperty(String key) { + return System.getProperty(key); + } + + protected boolean isAndroid() { + + String name = getSystemProperty("java.vm.name"); + if (name != null) { + String lcase = name.toLowerCase(); + return lcase.contains("dalvik"); + } + + name = getSystemProperty("java.vm.vendor"); + if (name != null) { + String lcase = name.toLowerCase(); + return lcase.contains("android"); + } + + return false; + } + + + @Override + public TextCodec getTextCodec() { + + if (isAndroid()) { + return new AndroidBase64Codec(); + } + + return new Base64Codec(); + } +} diff --git a/src/main/java/io/jsonwebtoken/impl/TextCodec.java b/src/main/java/io/jsonwebtoken/impl/TextCodec.java index caf955a8..44e8b931 100644 --- a/src/main/java/io/jsonwebtoken/impl/TextCodec.java +++ b/src/main/java/io/jsonwebtoken/impl/TextCodec.java @@ -17,7 +17,7 @@ package io.jsonwebtoken.impl; public interface TextCodec { - public static final TextCodec BASE64 = new Base64Codec(); + public static final TextCodec BASE64 = new DefaultTextCodecFactory().getTextCodec(); public static final TextCodec BASE64URL = new Base64UrlCodec(); String encode(String data); diff --git a/src/main/java/io/jsonwebtoken/impl/TextCodecFactory.java b/src/main/java/io/jsonwebtoken/impl/TextCodecFactory.java new file mode 100644 index 00000000..43fc429c --- /dev/null +++ b/src/main/java/io/jsonwebtoken/impl/TextCodecFactory.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.jsonwebtoken.impl; + +public interface TextCodecFactory { + + TextCodec getTextCodec(); +} diff --git a/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy b/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy index 72255b2c..32898b7b 100644 --- a/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy @@ -15,9 +15,8 @@ */ package io.jsonwebtoken -import org.testng.annotations.Test - -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class ExpiredJwtExceptionTest { diff --git a/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy b/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy index 27ec062f..c54b430d 100644 --- a/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy @@ -15,9 +15,8 @@ */ package io.jsonwebtoken -import org.testng.annotations.Test - -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class JwtHandlerAdapterTest { diff --git a/src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy b/src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy index 5309706c..1ea33fa9 100644 --- a/src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy @@ -16,13 +16,12 @@ package io.jsonwebtoken import io.jsonwebtoken.impl.TextCodec -import org.testng.annotations.Test import javax.crypto.spec.SecretKeySpec import java.security.SecureRandom -import static org.testng.Assert.* - +import org.junit.Test +import static org.junit.Assert.* class JwtParserTest { @@ -97,7 +96,7 @@ class JwtParserTest { Jwts.parser().setSigningKey(randomKey()).parse(bad); fail() } catch (SignatureException se) { - assertEquals se.getMessage(), "Unsupported signature algorithm '$badAlgorithmName'" + assertEquals se.getMessage(), "Unsupported signature algorithm '$badAlgorithmName'".toString() } } diff --git a/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy b/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy index afb731c7..cd7ffd70 100644 --- a/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy @@ -22,7 +22,6 @@ import io.jsonwebtoken.impl.TextCodec import io.jsonwebtoken.impl.crypto.EllipticCurveProvider import io.jsonwebtoken.impl.crypto.MacProvider import io.jsonwebtoken.impl.crypto.RsaProvider -import org.testng.annotations.Test import javax.crypto.Mac import javax.crypto.spec.SecretKeySpec @@ -31,7 +30,8 @@ import java.security.KeyPair import java.security.PrivateKey import java.security.PublicKey -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class JwtsTest { @@ -108,20 +108,20 @@ class JwtsTest { def token = Jwts.parser().parse(jwt); - assertEquals token.body, claims + assert token.body == claims } - @Test(expectedExceptions = IllegalArgumentException) + @Test(expected = IllegalArgumentException) void testParseNull() { Jwts.parser().parse(null) } - @Test(expectedExceptions = IllegalArgumentException) + @Test(expected = IllegalArgumentException) void testParseEmptyString() { Jwts.parser().parse('') } - @Test(expectedExceptions = IllegalArgumentException) + @Test(expected = IllegalArgumentException) void testParseWhitespaceString() { Jwts.parser().parse(' ') } @@ -537,10 +537,8 @@ class JwtsTest { def token = Jwts.parser().setSigningKey(key).parse(jwt); - assertEquals token.header, [alg: alg.name()] - - assertEquals token.body, claims - + assert [alg: alg.name()] == token.header + assert token.body == claims } static void testHmac(SignatureAlgorithm alg) { @@ -553,9 +551,8 @@ class JwtsTest { def token = Jwts.parser().setSigningKey(key).parse(jwt) - assertEquals token.header, [alg: alg.name()] - - assertEquals token.body, claims + assert token.header == [alg: alg.name()] + assert token.body == claims } static void testEC(SignatureAlgorithm alg, boolean verifyWithPrivateKey=false) { @@ -575,9 +572,8 @@ class JwtsTest { def token = Jwts.parser().setSigningKey(key).parse(jwt); - assertEquals token.header, [alg: alg.name()] - - assertEquals token.body, claims + assert token.header == [alg: alg.name()] + assert token.body == claims } } diff --git a/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy b/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy index 8a0b1736..77bf0e1a 100644 --- a/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy @@ -15,9 +15,8 @@ */ package io.jsonwebtoken -import org.testng.annotations.Test - -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class PrematureJwtExceptionTest { diff --git a/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy b/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy index 79f364a6..2a5757b8 100644 --- a/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy @@ -15,9 +15,8 @@ */ package io.jsonwebtoken -import org.testng.annotations.Test - -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class SignatureAlgorithmTest { @@ -38,7 +37,7 @@ class SignatureAlgorithmTest { assert alg.description != null && alg.description != "" } - @Test(expectedExceptions = SignatureException) + @Test(expected = SignatureException) void testUnrecognizedAlgorithmName() { SignatureAlgorithm.forName('whatever') } diff --git a/src/test/groovy/io/jsonwebtoken/impl/AndroidBase64CodecTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/AndroidBase64CodecTest.groovy new file mode 100644 index 00000000..54d53a23 --- /dev/null +++ b/src/test/groovy/io/jsonwebtoken/impl/AndroidBase64CodecTest.groovy @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.jsonwebtoken.impl + +import android.util.Base64 +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +import static org.easymock.EasyMock.* +import static org.junit.Assert.* +import static org.powermock.api.easymock.PowerMock.mockStatic +import static org.powermock.api.easymock.PowerMock.replayAll +import static org.powermock.api.easymock.PowerMock.verifyAll + +@RunWith(PowerMockRunner.class) +@PrepareForTest([Base64.class]) +class AndroidBase64CodecTest { + + @Test + public void testEncode() { + + mockStatic(Base64.class); + + byte[] bytes = new byte[32]; + String s = "foo"; + int flags = Base64.NO_PADDING | Base64.NO_WRAP; + + expect(Base64.encodeToString(same(bytes), eq(flags))).andReturn(s); + replayAll(); + + AndroidBase64Codec codec = new AndroidBase64Codec(); + + String val = codec.encode(bytes); + + verifyAll(); + assertEquals(val, s); + } + + @Test + public void testDecode() { + + mockStatic(Base64.class); + + byte[] bytes = new byte[32]; + String s = "foo"; + + expect(Base64.decode((String)same(s), eq(Base64.DEFAULT))).andReturn(bytes); + replayAll(); + + AndroidBase64Codec codec = new AndroidBase64Codec(); + + def val = codec.decode(s); + + verifyAll(); + assertSame bytes, val + } +} diff --git a/src/test/groovy/io/jsonwebtoken/impl/DefaultHeaderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/DefaultHeaderTest.groovy index f99f07f7..44b0fa23 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/DefaultHeaderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/DefaultHeaderTest.groovy @@ -15,8 +15,8 @@ */ package io.jsonwebtoken.impl -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultHeaderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsHeaderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsHeaderTest.groovy index e8c83124..9d43dfd9 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsHeaderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsHeaderTest.groovy @@ -15,8 +15,8 @@ */ package io.jsonwebtoken.impl -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultJwsHeaderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsTest.groovy index 309f372a..3acaf314 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwsTest.groovy @@ -17,8 +17,8 @@ package io.jsonwebtoken.impl import io.jsonwebtoken.JwsHeader import io.jsonwebtoken.Jwts -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultJwsTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwtBuilderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwtBuilderTest.groovy index 4401871c..9c517ef4 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/DefaultJwtBuilderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/DefaultJwtBuilderTest.groovy @@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.JsonMappingException import io.jsonwebtoken.Jwts import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.impl.crypto.MacProvider -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultJwtBuilderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/DefaultTextCodecFactoryTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/DefaultTextCodecFactoryTest.groovy new file mode 100644 index 00000000..cb4b746f --- /dev/null +++ b/src/test/groovy/io/jsonwebtoken/impl/DefaultTextCodecFactoryTest.groovy @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.jsonwebtoken.impl + +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +import static org.junit.Assert.* + +@RunWith(PowerMockRunner.class) +@PrepareForTest([System.class]) +class DefaultTextCodecFactoryTest { + + @Test + void testIsAndroidByVmName() { + + def factory = new DefaultTextCodecFactory() { + @Override + protected String getSystemProperty(String key) { + return 'dalvik' + } + } + + assertTrue factory.getTextCodec() instanceof AndroidBase64Codec + } + + @Test + void testIsAndroidByNullVmName() { + + def factory = new DefaultTextCodecFactory() { + @Override + protected String getSystemProperty(String key) { + if (key == 'java.vm.name') return null; + return 'android' + } + } + + assertTrue factory.getTextCodec() instanceof AndroidBase64Codec + } + + @Test + void testIsAndroidByNullVmNameAndNullVendorName() { + + def factory = new DefaultTextCodecFactory() { + @Override + protected String getSystemProperty(String key) { + return null + } + } + + assertFalse factory.getTextCodec() instanceof AndroidBase64Codec + } +} diff --git a/src/test/groovy/io/jsonwebtoken/impl/JwtMapTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/JwtMapTest.groovy index 6ea987d7..1b155b3e 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/JwtMapTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/JwtMapTest.groovy @@ -15,8 +15,8 @@ */ package io.jsonwebtoken.impl -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class JwtMapTest { @@ -115,6 +115,7 @@ class JwtMapTest { void testValues() { def m = new JwtMap() m.putAll([a: 'b', c: 'd']) - assertEquals( m.values(), ['b', 'd'] as Set) + def s = ['b', 'd'] + assertTrue m.values().containsAll(s) && s.containsAll(m.values()) } } diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignatureValidatorFactoryTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignatureValidatorFactoryTest.groovy index ab5f906f..04ec851d 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignatureValidatorFactoryTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignatureValidatorFactoryTest.groovy @@ -16,8 +16,8 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultSignatureValidatorFactoryTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignerFactoryTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignerFactoryTest.groovy index dfb92df7..d3139640 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignerFactoryTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultSignerFactoryTest.groovy @@ -16,11 +16,8 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm -import org.testng.annotations.Test - -import javax.crypto.spec.SecretKeySpec - -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class DefaultSignerFactoryTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveProviderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveProviderTest.groovy index bf14422c..d152df31 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveProviderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveProviderTest.groovy @@ -16,15 +16,14 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm -import org.testng.annotations.Test import java.security.KeyPair import java.security.NoSuchProviderException import java.security.interfaces.ECPrivateKey import java.security.interfaces.ECPublicKey -import static org.testng.Assert.* - +import org.junit.Test +import static org.junit.Assert.* class EllipticCurveProviderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignatureValidatorTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignatureValidatorTest.groovy index faf64ac9..e595bd89 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignatureValidatorTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignatureValidatorTest.groovy @@ -17,13 +17,13 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import java.security.InvalidKeyException import java.security.PublicKey import java.security.Signature -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class EllipticCurveSignatureValidatorTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignerTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignerTest.groovy index 889a3e1e..4587f1f6 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignerTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/EllipticCurveSignerTest.groovy @@ -17,14 +17,14 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import java.security.InvalidKeyException import java.security.KeyPair import java.security.PrivateKey import java.security.PublicKey -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class EllipticCurveSignerTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/MacProviderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/MacProviderTest.groovy index 7c2c59a5..ea3a87e5 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/MacProviderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/MacProviderTest.groovy @@ -16,10 +16,8 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm -import org.testng.annotations.Test - -import static org.testng.Assert.* - +import org.junit.Test +import static org.junit.Assert.* class MacProviderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/MacSignerTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/MacSignerTest.groovy index c0a5745e..f796beae 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/MacSignerTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/MacSignerTest.groovy @@ -17,8 +17,8 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* import javax.crypto.Mac import java.security.InvalidKeyException diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaProviderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaProviderTest.groovy index a7010a58..7887fc74 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaProviderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaProviderTest.groovy @@ -17,7 +17,6 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import java.security.InvalidAlgorithmParameterException import java.security.KeyPair @@ -26,7 +25,8 @@ import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey import java.security.spec.PSSParameterSpec -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class RsaProviderTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignatureValidatorTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignatureValidatorTest.groovy index bb17fdd4..2f4c1356 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignatureValidatorTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignatureValidatorTest.groovy @@ -17,7 +17,6 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import java.security.InvalidKeyException import java.security.KeyPair @@ -26,10 +25,8 @@ import java.security.PrivateKey import java.security.PublicKey import java.security.Signature -import static org.testng.Assert.assertEquals -import static org.testng.Assert.assertSame -import static org.testng.Assert.fail - +import org.junit.Test +import static org.junit.Assert.* class RsaSignatureValidatorTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignerTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignerTest.groovy index bd673a0b..39fe04c0 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignerTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/RsaSignerTest.groovy @@ -17,7 +17,6 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import javax.crypto.spec.SecretKeySpec import java.security.InvalidKeyException @@ -26,7 +25,8 @@ import java.security.KeyPairGenerator import java.security.PrivateKey import java.security.PublicKey -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class RsaSignerTest { diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/SignatureProviderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/SignatureProviderTest.groovy index 4e7c4022..e595231c 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/SignatureProviderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/SignatureProviderTest.groovy @@ -17,12 +17,12 @@ package io.jsonwebtoken.impl.crypto import io.jsonwebtoken.SignatureAlgorithm import io.jsonwebtoken.SignatureException -import org.testng.annotations.Test import java.security.NoSuchAlgorithmException import java.security.Signature -import static org.testng.Assert.* +import org.junit.Test +import static org.junit.Assert.* class SignatureProviderTest {