diff --git a/.travis.yml b/.travis.yml
index 4a9845db..9618dfb2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
# https://travis-ci.org/jwtk/jjwt
-dist: trusty
-sudo: required
+#sudo: required
language: java
jdk:
- openjdk7
@@ -9,16 +8,15 @@ jdk:
- oraclejdk9
- oraclejdk10
- openjdk10
- - oraclejdk-ea
- - openjdk11
+# - openjdk11
+# - oraclejdk-ea
before_install:
- export BUILD_COVERAGE="$([ $TRAVIS_JDK_VERSION == 'oraclejdk8' ] && echo 'true')"
-install: echo "No need to run mvn install -DskipTests then mvn install. Running mvn install."
+install: true
script: mvn install
after_success:
- - test -z "$BUILD_COVERAGE" || mvn clean test clover:check clover:clover coveralls:report
-
+ - test -z "$BUILD_COVERAGE" || { mvn clean clover:setup test && mvn -pl . clover:clover clover:check coveralls:report; }
diff --git a/NOTICE b/NOTICE
index 02cf1046..8004d561 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,4 +1,4 @@
-The io.jsonwebtoken.codec.impl.Base64 implementation is based on MigBase64 with modifications for Base64 URL support. This
+The Base64 implementation is based on MigBase64 with modifications for Base64 URL support. This
class's copyright and license notice have been retained and are repeated here per that code's requirements:
**** BEGIN MIGBASE64 NOTICE *****
diff --git a/README.md b/README.md
index 74970263..faf9bbb7 100644
--- a/README.md
+++ b/README.md
@@ -89,7 +89,7 @@ Most complexity is hidden behind a convenient and readable builder-based [fluent
```java
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
-import io.jsonwebtoken.impl.crypto.MacProvider;
+import MacProvider; //TODO: clean up via https://github.com/jwtk/jjwt/issues/350
import java.security.Key;
// We need a signing key, so we'll create one just for this example. Usually
@@ -154,7 +154,7 @@ You can use the following rules on your Android projects (see [Proguard Exclusio
-keepnames interface io.jsonwebtoken.* { *; }
-dontwarn javax.xml.bind.DatatypeConverter
--dontwarn io.jsonwebtoken.impl.Base64Codec
+-dontwarn Base64Codec
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames interface com.fasterxml.jackson.** { *; }
diff --git a/api/pom.xml b/api/pom.xml
new file mode 100644
index 00000000..0e6ad7e4
--- /dev/null
+++ b/api/pom.xml
@@ -0,0 +1,36 @@
+
+
+
+
+ 4.0.0
+
+
+ io.jsonwebtoken
+ jjwt-root
+ 0.10.0-SNAPSHOT
+ ../pom.xml
+
+
+ jjwt-api
+ JJWT :: API
+ jar
+
+
+ ${basedir}/..
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/jsonwebtoken/ClaimJwtException.java b/api/src/main/java/io/jsonwebtoken/ClaimJwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/ClaimJwtException.java
rename to api/src/main/java/io/jsonwebtoken/ClaimJwtException.java
diff --git a/src/main/java/io/jsonwebtoken/Claims.java b/api/src/main/java/io/jsonwebtoken/Claims.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/Claims.java
rename to api/src/main/java/io/jsonwebtoken/Claims.java
diff --git a/src/main/java/io/jsonwebtoken/ClaimsMutator.java b/api/src/main/java/io/jsonwebtoken/ClaimsMutator.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/ClaimsMutator.java
rename to api/src/main/java/io/jsonwebtoken/ClaimsMutator.java
diff --git a/src/main/java/io/jsonwebtoken/Clock.java b/api/src/main/java/io/jsonwebtoken/Clock.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/Clock.java
rename to api/src/main/java/io/jsonwebtoken/Clock.java
diff --git a/src/main/java/io/jsonwebtoken/CompressionCodec.java b/api/src/main/java/io/jsonwebtoken/CompressionCodec.java
similarity index 87%
rename from src/main/java/io/jsonwebtoken/CompressionCodec.java
rename to api/src/main/java/io/jsonwebtoken/CompressionCodec.java
index b17153d3..47e54761 100644
--- a/src/main/java/io/jsonwebtoken/CompressionCodec.java
+++ b/api/src/main/java/io/jsonwebtoken/CompressionCodec.java
@@ -18,16 +18,16 @@ package io.jsonwebtoken;
/**
* Compresses and decompresses byte arrays according to a compression algorithm.
*
- * @see io.jsonwebtoken.impl.compression.DeflateCompressionCodec
- * @see io.jsonwebtoken.impl.compression.GzipCompressionCodec
+ * @see CompressionCodecs#DEFLATE
+ * @see CompressionCodecs#GZIP
* @since 0.6.0
*/
public interface CompressionCodec {
/**
- * The algorithm name to use as the JWT's {@code zip} header value.
+ * The compression algorithm name to use as the JWT's {@code zip} header value.
*
- * @return the algorithm name to use as the JWT's {@code zip} header value.
+ * @return the compression algorithm name to use as the JWT's {@code zip} header value.
*/
String getAlgorithmName();
diff --git a/src/main/java/io/jsonwebtoken/CompressionCodecResolver.java b/api/src/main/java/io/jsonwebtoken/CompressionCodecResolver.java
similarity index 90%
rename from src/main/java/io/jsonwebtoken/CompressionCodecResolver.java
rename to api/src/main/java/io/jsonwebtoken/CompressionCodecResolver.java
index 65dc7980..50ebe08f 100644
--- a/src/main/java/io/jsonwebtoken/CompressionCodecResolver.java
+++ b/api/src/main/java/io/jsonwebtoken/CompressionCodecResolver.java
@@ -20,8 +20,8 @@ package io.jsonwebtoken;
* can use to decompress the JWT body.
*
*
JJWT's default {@link JwtParser} implementation supports both the
- * {@link io.jsonwebtoken.impl.compression.DeflateCompressionCodec DEFLATE}
- * and {@link io.jsonwebtoken.impl.compression.GzipCompressionCodec GZIP} algorithms by default - you do not need to
+ * {@link CompressionCodecs#DEFLATE DEFLATE}
+ * and {@link CompressionCodecs#GZIP GZIP} algorithms by default - you do not need to
* specify a {@code CompressionCodecResolver} in these cases.
*
*
However, if you want to use a compression algorithm other than {@code DEF} or {@code GZIP}, you must implement
diff --git a/src/main/java/io/jsonwebtoken/CompressionCodecs.java b/api/src/main/java/io/jsonwebtoken/CompressionCodecs.java
similarity index 66%
rename from src/main/java/io/jsonwebtoken/CompressionCodecs.java
rename to api/src/main/java/io/jsonwebtoken/CompressionCodecs.java
index 4374197a..4a2fece6 100644
--- a/src/main/java/io/jsonwebtoken/CompressionCodecs.java
+++ b/api/src/main/java/io/jsonwebtoken/CompressionCodecs.java
@@ -1,7 +1,6 @@
package io.jsonwebtoken;
-import io.jsonwebtoken.impl.compression.DeflateCompressionCodec;
-import io.jsonwebtoken.impl.compression.GzipCompressionCodec;
+import io.jsonwebtoken.lang.Classes;
/**
* Provides default implementations of the {@link CompressionCodec} interface.
@@ -12,15 +11,15 @@ import io.jsonwebtoken.impl.compression.GzipCompressionCodec;
*/
public final class CompressionCodecs {
- private static final CompressionCodecs INSTANCE = new CompressionCodecs();
-
- private CompressionCodecs() {} //prevent external instantiation
+ private CompressionCodecs() {
+ } //prevent external instantiation
/**
* Codec implementing the JWA standard
* deflate compression algorithm
*/
- public static final CompressionCodec DEFLATE = new DeflateCompressionCodec();
+ public static final CompressionCodec DEFLATE =
+ Classes.newInstance("io.jsonwebtoken.impl.compression.DeflateCompressionCodec");
/**
* Codec implementing the gzip compression algorithm.
@@ -29,6 +28,7 @@ public final class CompressionCodecs {
* that all parties accessing the token support the gzip algorithm.
*
If you're concerned about compatibility, the {@link #DEFLATE DEFLATE} code is JWA standards-compliant.
*/
- public static final CompressionCodec GZIP = new GzipCompressionCodec();
+ public static final CompressionCodec GZIP =
+ Classes.newInstance("io.jsonwebtoken.impl.compression.GzipCompressionCodec");
}
diff --git a/src/main/java/io/jsonwebtoken/CompressionException.java b/api/src/main/java/io/jsonwebtoken/CompressionException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/CompressionException.java
rename to api/src/main/java/io/jsonwebtoken/CompressionException.java
diff --git a/src/main/java/io/jsonwebtoken/ExpiredJwtException.java b/api/src/main/java/io/jsonwebtoken/ExpiredJwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/ExpiredJwtException.java
rename to api/src/main/java/io/jsonwebtoken/ExpiredJwtException.java
diff --git a/src/main/java/io/jsonwebtoken/Header.java b/api/src/main/java/io/jsonwebtoken/Header.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/Header.java
rename to api/src/main/java/io/jsonwebtoken/Header.java
diff --git a/src/main/java/io/jsonwebtoken/IncorrectClaimException.java b/api/src/main/java/io/jsonwebtoken/IncorrectClaimException.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/IncorrectClaimException.java
rename to api/src/main/java/io/jsonwebtoken/IncorrectClaimException.java
index 860a4d84..df68fe1e 100644
--- a/src/main/java/io/jsonwebtoken/IncorrectClaimException.java
+++ b/api/src/main/java/io/jsonwebtoken/IncorrectClaimException.java
@@ -22,6 +22,7 @@ package io.jsonwebtoken;
* @since 0.6
*/
public class IncorrectClaimException extends InvalidClaimException {
+
public IncorrectClaimException(Header header, Claims claims, String message) {
super(header, claims, message);
}
diff --git a/src/main/java/io/jsonwebtoken/InvalidClaimException.java b/api/src/main/java/io/jsonwebtoken/InvalidClaimException.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/InvalidClaimException.java
rename to api/src/main/java/io/jsonwebtoken/InvalidClaimException.java
index 8880792c..fbca6cab 100644
--- a/src/main/java/io/jsonwebtoken/InvalidClaimException.java
+++ b/api/src/main/java/io/jsonwebtoken/InvalidClaimException.java
@@ -25,6 +25,7 @@ package io.jsonwebtoken;
* @since 0.6
*/
public class InvalidClaimException extends ClaimJwtException {
+
private String claimName;
private Object claimValue;
diff --git a/src/main/java/io/jsonwebtoken/Jws.java b/api/src/main/java/io/jsonwebtoken/Jws.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/Jws.java
rename to api/src/main/java/io/jsonwebtoken/Jws.java
diff --git a/src/main/java/io/jsonwebtoken/JwsHeader.java b/api/src/main/java/io/jsonwebtoken/JwsHeader.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/JwsHeader.java
rename to api/src/main/java/io/jsonwebtoken/JwsHeader.java
diff --git a/src/main/java/io/jsonwebtoken/Jwt.java b/api/src/main/java/io/jsonwebtoken/Jwt.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/Jwt.java
rename to api/src/main/java/io/jsonwebtoken/Jwt.java
diff --git a/src/main/java/io/jsonwebtoken/JwtBuilder.java b/api/src/main/java/io/jsonwebtoken/JwtBuilder.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/JwtBuilder.java
rename to api/src/main/java/io/jsonwebtoken/JwtBuilder.java
index 9db9568c..b7b5bc3f 100644
--- a/src/main/java/io/jsonwebtoken/JwtBuilder.java
+++ b/api/src/main/java/io/jsonwebtoken/JwtBuilder.java
@@ -15,7 +15,7 @@
*/
package io.jsonwebtoken;
-import io.jsonwebtoken.codec.Encoder;
+import io.jsonwebtoken.io.Encoder;
import io.jsonwebtoken.io.Serializer;
import java.security.Key;
diff --git a/src/main/java/io/jsonwebtoken/JwtException.java b/api/src/main/java/io/jsonwebtoken/JwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/JwtException.java
rename to api/src/main/java/io/jsonwebtoken/JwtException.java
diff --git a/src/main/java/io/jsonwebtoken/JwtHandler.java b/api/src/main/java/io/jsonwebtoken/JwtHandler.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/JwtHandler.java
rename to api/src/main/java/io/jsonwebtoken/JwtHandler.java
diff --git a/src/main/java/io/jsonwebtoken/JwtHandlerAdapter.java b/api/src/main/java/io/jsonwebtoken/JwtHandlerAdapter.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/JwtHandlerAdapter.java
rename to api/src/main/java/io/jsonwebtoken/JwtHandlerAdapter.java
diff --git a/src/main/java/io/jsonwebtoken/JwtParser.java b/api/src/main/java/io/jsonwebtoken/JwtParser.java
similarity index 98%
rename from src/main/java/io/jsonwebtoken/JwtParser.java
rename to api/src/main/java/io/jsonwebtoken/JwtParser.java
index 3fd38f15..9b76e2ea 100644
--- a/src/main/java/io/jsonwebtoken/JwtParser.java
+++ b/api/src/main/java/io/jsonwebtoken/JwtParser.java
@@ -15,8 +15,7 @@
*/
package io.jsonwebtoken;
-import io.jsonwebtoken.codec.Decoder;
-import io.jsonwebtoken.impl.DefaultClock;
+import io.jsonwebtoken.io.Decoder;
import io.jsonwebtoken.io.Deserializer;
import java.security.Key;
@@ -131,7 +130,7 @@ public interface JwtParser {
/**
* Sets the {@link Clock} that determines the timestamp to use when validating the parsed JWT.
- * The parser uses a {@link DefaultClock DefaultClock} instance by default.
+ * The parser uses a default Clock implementation that simply returns {@code new Date()} when called.
*
* @param clock a {@code Clock} object to return the timestamp to use when validating the parsed JWT.
* @return the parser for method chaining.
@@ -259,8 +258,8 @@ public interface JwtParser {
* the same behavior.
*
Default Support
*
JJWT's default {@link JwtParser} implementation supports both the
- * {@link io.jsonwebtoken.impl.compression.DeflateCompressionCodec DEFLATE}
- * and {@link io.jsonwebtoken.impl.compression.GzipCompressionCodec GZIP} algorithms by default - you do not need to
+ * {@link CompressionCodecs#DEFLATE DEFLATE}
+ * and {@link CompressionCodecs#GZIP GZIP} algorithms by default - you do not need to
* specify a {@code CompressionCodecResolver} in these cases.
*
However, if you want to use a compression algorithm other than {@code DEF} or {@code GZIP}, you must implement
* your own {@link CompressionCodecResolver} and specify that via this method and also when
diff --git a/src/main/java/io/jsonwebtoken/Jwts.java b/api/src/main/java/io/jsonwebtoken/Jwts.java
similarity index 82%
rename from src/main/java/io/jsonwebtoken/Jwts.java
rename to api/src/main/java/io/jsonwebtoken/Jwts.java
index ebac88e7..2e4b2caf 100644
--- a/src/main/java/io/jsonwebtoken/Jwts.java
+++ b/api/src/main/java/io/jsonwebtoken/Jwts.java
@@ -15,11 +15,7 @@
*/
package io.jsonwebtoken;
-import io.jsonwebtoken.impl.DefaultClaims;
-import io.jsonwebtoken.impl.DefaultHeader;
-import io.jsonwebtoken.impl.DefaultJwsHeader;
-import io.jsonwebtoken.impl.DefaultJwtBuilder;
-import io.jsonwebtoken.impl.DefaultJwtParser;
+import io.jsonwebtoken.lang.Classes;
import java.util.Map;
@@ -31,7 +27,10 @@ import java.util.Map;
*/
public final class Jwts {
- private Jwts(){}
+ private static final Class[] MAP_ARG = new Class[]{Map.class};
+
+ private Jwts() {
+ }
/**
* Creates a new {@link Header} instance suitable for plaintext (not digitally signed) JWTs. As this
@@ -41,7 +40,7 @@ public final class Jwts {
* @return a new {@link Header} instance suitable for plaintext (not digitally signed) JWTs.
*/
public static Header header() {
- return new DefaultHeader();
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultHeader");
}
/**
@@ -52,7 +51,7 @@ public final class Jwts {
* @return a new {@link Header} instance suitable for plaintext (not digitally signed) JWTs.
*/
public static Header header(Map header) {
- return new DefaultHeader(header);
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultHeader", MAP_ARG, header);
}
/**
@@ -62,7 +61,7 @@ public final class Jwts {
* @see JwtBuilder#setHeader(Header)
*/
public static JwsHeader jwsHeader() {
- return new DefaultJwsHeader();
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwsHeader");
}
/**
@@ -74,7 +73,7 @@ public final class Jwts {
* @see JwtBuilder#setHeader(Header)
*/
public static JwsHeader jwsHeader(Map header) {
- return new DefaultJwsHeader(header);
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwsHeader", MAP_ARG, header);
}
/**
@@ -83,7 +82,7 @@ public final class Jwts {
* @return a new {@link Claims} instance to be used as a JWT body.
*/
public static Claims claims() {
- return new DefaultClaims();
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultClaims");
}
/**
@@ -93,7 +92,7 @@ public final class Jwts {
* @return a new {@link Claims} instance populated with the specified name/value pairs.
*/
public static Claims claims(Map claims) {
- return new DefaultClaims(claims);
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultClaims", MAP_ARG, claims);
}
/**
@@ -102,7 +101,7 @@ public final class Jwts {
* @return a new {@link JwtParser} instance that can be configured and then used to parse JWT strings.
*/
public static JwtParser parser() {
- return new DefaultJwtParser();
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwtParser");
}
/**
@@ -113,6 +112,6 @@ public final class Jwts {
* strings.
*/
public static JwtBuilder builder() {
- return new DefaultJwtBuilder();
+ return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwtBuilder");
}
}
diff --git a/src/main/java/io/jsonwebtoken/MalformedJwtException.java b/api/src/main/java/io/jsonwebtoken/MalformedJwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/MalformedJwtException.java
rename to api/src/main/java/io/jsonwebtoken/MalformedJwtException.java
diff --git a/src/main/java/io/jsonwebtoken/MissingClaimException.java b/api/src/main/java/io/jsonwebtoken/MissingClaimException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/MissingClaimException.java
rename to api/src/main/java/io/jsonwebtoken/MissingClaimException.java
diff --git a/src/main/java/io/jsonwebtoken/PrematureJwtException.java b/api/src/main/java/io/jsonwebtoken/PrematureJwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/PrematureJwtException.java
rename to api/src/main/java/io/jsonwebtoken/PrematureJwtException.java
diff --git a/src/main/java/io/jsonwebtoken/RequiredTypeException.java b/api/src/main/java/io/jsonwebtoken/RequiredTypeException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/RequiredTypeException.java
rename to api/src/main/java/io/jsonwebtoken/RequiredTypeException.java
diff --git a/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java b/api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/SignatureAlgorithm.java
rename to api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java
diff --git a/src/main/java/io/jsonwebtoken/SignatureException.java b/api/src/main/java/io/jsonwebtoken/SignatureException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/SignatureException.java
rename to api/src/main/java/io/jsonwebtoken/SignatureException.java
diff --git a/src/main/java/io/jsonwebtoken/SigningKeyResolver.java b/api/src/main/java/io/jsonwebtoken/SigningKeyResolver.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/SigningKeyResolver.java
rename to api/src/main/java/io/jsonwebtoken/SigningKeyResolver.java
diff --git a/src/main/java/io/jsonwebtoken/SigningKeyResolverAdapter.java b/api/src/main/java/io/jsonwebtoken/SigningKeyResolverAdapter.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/SigningKeyResolverAdapter.java
rename to api/src/main/java/io/jsonwebtoken/SigningKeyResolverAdapter.java
diff --git a/src/main/java/io/jsonwebtoken/UnsupportedJwtException.java b/api/src/main/java/io/jsonwebtoken/UnsupportedJwtException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/UnsupportedJwtException.java
rename to api/src/main/java/io/jsonwebtoken/UnsupportedJwtException.java
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/Base64.java b/api/src/main/java/io/jsonwebtoken/io/Base64.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/codec/impl/Base64.java
rename to api/src/main/java/io/jsonwebtoken/io/Base64.java
index 238b35f9..1cbaf2a9 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/Base64.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64.java
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
import java.util.Arrays;
@@ -18,6 +18,7 @@ import java.util.Arrays;
*
* @author Mikael Grev
* @author Les Hazlewood
+ * @since 0.10.0
*/
@SuppressWarnings("Duplicates")
final class Base64 { //final and package-protected on purpose
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/Base64Decoder.java b/api/src/main/java/io/jsonwebtoken/io/Base64Decoder.java
similarity index 59%
rename from src/main/java/io/jsonwebtoken/codec/impl/Base64Decoder.java
rename to api/src/main/java/io/jsonwebtoken/io/Base64Decoder.java
index 66175d5c..b2798a19 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/Base64Decoder.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64Decoder.java
@@ -1,12 +1,13 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
-import io.jsonwebtoken.codec.Decoder;
-import io.jsonwebtoken.codec.DecodingException;
import io.jsonwebtoken.lang.Assert;
-public class Base64Decoder extends Base64Support implements Decoder {
+/**
+ * @since 0.10.0
+ */
+class Base64Decoder extends Base64Support implements Decoder {
- public Base64Decoder() {
+ Base64Decoder() {
super(Base64.DEFAULT);
}
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/Base64Encoder.java b/api/src/main/java/io/jsonwebtoken/io/Base64Encoder.java
similarity index 60%
rename from src/main/java/io/jsonwebtoken/codec/impl/Base64Encoder.java
rename to api/src/main/java/io/jsonwebtoken/io/Base64Encoder.java
index f6ff1676..feff18c0 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/Base64Encoder.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64Encoder.java
@@ -1,12 +1,13 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
-import io.jsonwebtoken.codec.Encoder;
-import io.jsonwebtoken.codec.EncodingException;
import io.jsonwebtoken.lang.Assert;
-public class Base64Encoder extends Base64Support implements Encoder {
+/**
+ * @since 0.10.0
+ */
+class Base64Encoder extends Base64Support implements Encoder {
- public Base64Encoder() {
+ Base64Encoder() {
super(Base64.DEFAULT);
}
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/Base64Support.java b/api/src/main/java/io/jsonwebtoken/io/Base64Support.java
similarity index 74%
rename from src/main/java/io/jsonwebtoken/codec/impl/Base64Support.java
rename to api/src/main/java/io/jsonwebtoken/io/Base64Support.java
index 77bdd044..cc954b41 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/Base64Support.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64Support.java
@@ -1,8 +1,11 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
import io.jsonwebtoken.lang.Assert;
-public class Base64Support {
+/**
+ * @since 0.10.0
+ */
+class Base64Support {
protected final Base64 base64;
diff --git a/api/src/main/java/io/jsonwebtoken/io/Base64UrlDecoder.java b/api/src/main/java/io/jsonwebtoken/io/Base64UrlDecoder.java
new file mode 100644
index 00000000..a648061c
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64UrlDecoder.java
@@ -0,0 +1,11 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+class Base64UrlDecoder extends Base64Decoder {
+
+ Base64UrlDecoder() {
+ super(Base64.URL_SAFE);
+ }
+}
diff --git a/api/src/main/java/io/jsonwebtoken/io/Base64UrlEncoder.java b/api/src/main/java/io/jsonwebtoken/io/Base64UrlEncoder.java
new file mode 100644
index 00000000..ca1e4072
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Base64UrlEncoder.java
@@ -0,0 +1,11 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+class Base64UrlEncoder extends Base64Encoder {
+
+ Base64UrlEncoder() {
+ super(Base64.URL_SAFE);
+ }
+}
diff --git a/src/main/java/io/jsonwebtoken/codec/CodecException.java b/api/src/main/java/io/jsonwebtoken/io/CodecException.java
similarity index 51%
rename from src/main/java/io/jsonwebtoken/codec/CodecException.java
rename to api/src/main/java/io/jsonwebtoken/io/CodecException.java
index aa274328..223c875d 100644
--- a/src/main/java/io/jsonwebtoken/codec/CodecException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/CodecException.java
@@ -1,11 +1,9 @@
-package io.jsonwebtoken.codec;
-
-import io.jsonwebtoken.JwtException;
+package io.jsonwebtoken.io;
/**
* @since 0.10.0
*/
-public class CodecException extends JwtException {
+public class CodecException extends IOException {
public CodecException(String message, Throwable cause) {
super(message, cause);
diff --git a/api/src/main/java/io/jsonwebtoken/io/Decoder.java b/api/src/main/java/io/jsonwebtoken/io/Decoder.java
new file mode 100644
index 00000000..bceb42a6
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Decoder.java
@@ -0,0 +1,9 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+public interface Decoder {
+
+ R decode(T t) throws DecodingException;
+}
diff --git a/api/src/main/java/io/jsonwebtoken/io/Decoders.java b/api/src/main/java/io/jsonwebtoken/io/Decoders.java
new file mode 100644
index 00000000..e81f9b1e
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Decoders.java
@@ -0,0 +1,13 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+public final class Decoders {
+
+ public static final Decoder BASE64 = new ExceptionPropagatingDecoder<>(new Base64Decoder());
+ public static final Decoder BASE64URL = new ExceptionPropagatingDecoder<>(new Base64UrlDecoder());
+
+ private Decoders() { //prevent instantiation
+ }
+}
diff --git a/src/main/java/io/jsonwebtoken/codec/DecodingException.java b/api/src/main/java/io/jsonwebtoken/io/DecodingException.java
similarity index 85%
rename from src/main/java/io/jsonwebtoken/codec/DecodingException.java
rename to api/src/main/java/io/jsonwebtoken/io/DecodingException.java
index a3a8446e..8ad60a5a 100644
--- a/src/main/java/io/jsonwebtoken/codec/DecodingException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/DecodingException.java
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec;
+package io.jsonwebtoken.io;
/**
* @since 0.10.0
diff --git a/src/main/java/io/jsonwebtoken/io/DeserializationException.java b/api/src/main/java/io/jsonwebtoken/io/DeserializationException.java
similarity index 91%
rename from src/main/java/io/jsonwebtoken/io/DeserializationException.java
rename to api/src/main/java/io/jsonwebtoken/io/DeserializationException.java
index 33ab20e1..4431d7f8 100644
--- a/src/main/java/io/jsonwebtoken/io/DeserializationException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/DeserializationException.java
@@ -1,5 +1,8 @@
package io.jsonwebtoken.io;
+/**
+ * @since 0.10.0
+ */
public class DeserializationException extends SerialException {
public DeserializationException(String msg) {
diff --git a/src/main/java/io/jsonwebtoken/io/Deserializer.java b/api/src/main/java/io/jsonwebtoken/io/Deserializer.java
similarity index 84%
rename from src/main/java/io/jsonwebtoken/io/Deserializer.java
rename to api/src/main/java/io/jsonwebtoken/io/Deserializer.java
index 7a076fe5..d970dfaf 100644
--- a/src/main/java/io/jsonwebtoken/io/Deserializer.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Deserializer.java
@@ -1,5 +1,8 @@
package io.jsonwebtoken.io;
+/**
+ * @since 0.10.0
+ */
public interface Deserializer {
T deserialize(byte[] bytes) throws DeserializationException;
diff --git a/api/src/main/java/io/jsonwebtoken/io/Encoder.java b/api/src/main/java/io/jsonwebtoken/io/Encoder.java
new file mode 100644
index 00000000..0532ded2
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Encoder.java
@@ -0,0 +1,9 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+public interface Encoder {
+
+ R encode(T t) throws EncodingException;
+}
diff --git a/api/src/main/java/io/jsonwebtoken/io/Encoders.java b/api/src/main/java/io/jsonwebtoken/io/Encoders.java
new file mode 100644
index 00000000..2d6a4150
--- /dev/null
+++ b/api/src/main/java/io/jsonwebtoken/io/Encoders.java
@@ -0,0 +1,13 @@
+package io.jsonwebtoken.io;
+
+/**
+ * @since 0.10.0
+ */
+public final class Encoders {
+
+ public static final Encoder BASE64 = new ExceptionPropagatingEncoder<>(new Base64Encoder());
+ public static final Encoder BASE64URL = new ExceptionPropagatingEncoder<>(new Base64UrlEncoder());
+
+ private Encoders() { //prevent instantiation
+ }
+}
diff --git a/src/main/java/io/jsonwebtoken/codec/EncodingException.java b/api/src/main/java/io/jsonwebtoken/io/EncodingException.java
similarity index 85%
rename from src/main/java/io/jsonwebtoken/codec/EncodingException.java
rename to api/src/main/java/io/jsonwebtoken/io/EncodingException.java
index d538d12b..dd82bd74 100644
--- a/src/main/java/io/jsonwebtoken/codec/EncodingException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/EncodingException.java
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec;
+package io.jsonwebtoken.io;
/**
* @since 0.10.0
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoder.java b/api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingDecoder.java
similarity index 69%
rename from src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoder.java
rename to api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingDecoder.java
index 1e186e00..23e28a71 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoder.java
+++ b/api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingDecoder.java
@@ -1,14 +1,15 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
-import io.jsonwebtoken.codec.Decoder;
-import io.jsonwebtoken.codec.DecodingException;
import io.jsonwebtoken.lang.Assert;
-public class ExceptionPropagatingDecoder implements Decoder {
+/**
+ * @since 0.10.0
+ */
+class ExceptionPropagatingDecoder implements Decoder {
private final Decoder decoder;
- public ExceptionPropagatingDecoder(Decoder decoder) {
+ ExceptionPropagatingDecoder(Decoder decoder) {
Assert.notNull(decoder, "Decoder cannot be null.");
this.decoder = decoder;
}
diff --git a/src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoder.java b/api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingEncoder.java
similarity index 65%
rename from src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoder.java
rename to api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingEncoder.java
index ab21278e..ba9dca0d 100644
--- a/src/main/java/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoder.java
+++ b/api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingEncoder.java
@@ -1,14 +1,15 @@
-package io.jsonwebtoken.codec.impl;
+package io.jsonwebtoken.io;
-import io.jsonwebtoken.codec.Encoder;
-import io.jsonwebtoken.codec.EncodingException;
import io.jsonwebtoken.lang.Assert;
-public class ExceptionPropagatingEncoder implements Encoder {
+/**
+ * @since 0.10.0
+ */
+class ExceptionPropagatingEncoder implements Encoder {
- private final Encoder encoder;
+ private final Encoder encoder;
- public ExceptionPropagatingEncoder(Encoder encoder) {
+ ExceptionPropagatingEncoder(Encoder encoder) {
Assert.notNull(encoder, "Encoder cannot be null.");
this.encoder = encoder;
}
diff --git a/src/main/java/io/jsonwebtoken/io/IOException.java b/api/src/main/java/io/jsonwebtoken/io/IOException.java
similarity index 91%
rename from src/main/java/io/jsonwebtoken/io/IOException.java
rename to api/src/main/java/io/jsonwebtoken/io/IOException.java
index 68f0fa73..14f23c69 100644
--- a/src/main/java/io/jsonwebtoken/io/IOException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/IOException.java
@@ -2,6 +2,9 @@ package io.jsonwebtoken.io;
import io.jsonwebtoken.JwtException;
+/**
+ * @since 0.10.0
+ */
public class IOException extends JwtException {
public IOException(String msg) {
diff --git a/src/main/java/io/jsonwebtoken/io/SerialException.java b/api/src/main/java/io/jsonwebtoken/io/SerialException.java
similarity index 90%
rename from src/main/java/io/jsonwebtoken/io/SerialException.java
rename to api/src/main/java/io/jsonwebtoken/io/SerialException.java
index e653cd22..8207a9cd 100644
--- a/src/main/java/io/jsonwebtoken/io/SerialException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/SerialException.java
@@ -1,5 +1,8 @@
package io.jsonwebtoken.io;
+/**
+ * @since 0.10.0
+ */
public class SerialException extends IOException {
public SerialException(String msg) {
diff --git a/src/main/java/io/jsonwebtoken/io/SerializationException.java b/api/src/main/java/io/jsonwebtoken/io/SerializationException.java
similarity index 91%
rename from src/main/java/io/jsonwebtoken/io/SerializationException.java
rename to api/src/main/java/io/jsonwebtoken/io/SerializationException.java
index b5d9f3be..5a9a03c2 100644
--- a/src/main/java/io/jsonwebtoken/io/SerializationException.java
+++ b/api/src/main/java/io/jsonwebtoken/io/SerializationException.java
@@ -1,5 +1,8 @@
package io.jsonwebtoken.io;
+/**
+ * @since 0.10.0
+ */
public class SerializationException extends SerialException {
public SerializationException(String msg) {
diff --git a/src/main/java/io/jsonwebtoken/io/Serializer.java b/api/src/main/java/io/jsonwebtoken/io/Serializer.java
similarity index 83%
rename from src/main/java/io/jsonwebtoken/io/Serializer.java
rename to api/src/main/java/io/jsonwebtoken/io/Serializer.java
index 9d1b42ec..6129c7c6 100644
--- a/src/main/java/io/jsonwebtoken/io/Serializer.java
+++ b/api/src/main/java/io/jsonwebtoken/io/Serializer.java
@@ -1,5 +1,8 @@
package io.jsonwebtoken.io;
+/**
+ * @since 0.10.0
+ */
public interface Serializer {
byte[] serialize(T t) throws SerializationException;
diff --git a/src/main/java/io/jsonwebtoken/lang/Arrays.java b/api/src/main/java/io/jsonwebtoken/lang/Arrays.java
similarity index 73%
rename from src/main/java/io/jsonwebtoken/lang/Arrays.java
rename to api/src/main/java/io/jsonwebtoken/lang/Arrays.java
index c9a074bf..600c1658 100644
--- a/src/main/java/io/jsonwebtoken/lang/Arrays.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Arrays.java
@@ -5,10 +5,7 @@ package io.jsonwebtoken.lang;
*/
public final class Arrays {
- //for code coverage
- private static final Arrays INSTANCE = new Arrays();
-
- private Arrays(){}
+ private Arrays(){} //prevent instantiation
public static int length(byte[] bytes) {
return bytes != null ? bytes.length : 0;
diff --git a/src/main/java/io/jsonwebtoken/lang/Assert.java b/api/src/main/java/io/jsonwebtoken/lang/Assert.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/lang/Assert.java
rename to api/src/main/java/io/jsonwebtoken/lang/Assert.java
index f5e592c3..7c9e7c36 100644
--- a/src/main/java/io/jsonwebtoken/lang/Assert.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Assert.java
@@ -20,10 +20,7 @@ import java.util.Map;
public final class Assert {
- //for code coverage
- private static final Assert INSTANCE = new Assert();
-
- private Assert(){}
+ private Assert(){} //prevent instantiation
/**
* Assert a boolean expression, throwing IllegalArgumentException
diff --git a/src/main/java/io/jsonwebtoken/lang/Classes.java b/api/src/main/java/io/jsonwebtoken/lang/Classes.java
similarity index 96%
rename from src/main/java/io/jsonwebtoken/lang/Classes.java
rename to api/src/main/java/io/jsonwebtoken/lang/Classes.java
index fb592a65..22c27c00 100644
--- a/src/main/java/io/jsonwebtoken/lang/Classes.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Classes.java
@@ -23,9 +23,7 @@ import java.lang.reflect.Constructor;
*/
public final class Classes {
- private static final Classes INSTANCE = new Classes();
-
- private Classes() {}
+ private Classes() {} //prevent instantiation
/**
* @since 0.1
@@ -137,6 +135,12 @@ public final class Classes {
return (T)newInstance(forName(fqcn));
}
+ public static T newInstance(String fqcn, Class[] ctorArgTypes, Object... args) {
+ Class clazz = forName(fqcn);
+ Constructor ctor = getConstructor(clazz, ctorArgTypes);
+ return instantiate(ctor, args);
+ }
+
@SuppressWarnings("unchecked")
public static T newInstance(String fqcn, Object... args) {
return (T)newInstance(forName(fqcn), args);
diff --git a/src/main/java/io/jsonwebtoken/lang/Collections.java b/api/src/main/java/io/jsonwebtoken/lang/Collections.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/lang/Collections.java
rename to api/src/main/java/io/jsonwebtoken/lang/Collections.java
index 88b10dfb..d775a002 100644
--- a/src/main/java/io/jsonwebtoken/lang/Collections.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Collections.java
@@ -26,10 +26,7 @@ import java.util.Properties;
public final class Collections {
- //for code coverage
- private static final Collections INSTANCE = new Collections();
-
- private Collections(){}
+ private Collections(){} //prevent instantiation
/**
* Return true if the supplied Collection is null
diff --git a/src/main/java/io/jsonwebtoken/lang/DateFormats.java b/api/src/main/java/io/jsonwebtoken/lang/DateFormats.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/lang/DateFormats.java
rename to api/src/main/java/io/jsonwebtoken/lang/DateFormats.java
diff --git a/src/main/java/io/jsonwebtoken/lang/InstantiationException.java b/api/src/main/java/io/jsonwebtoken/lang/InstantiationException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/lang/InstantiationException.java
rename to api/src/main/java/io/jsonwebtoken/lang/InstantiationException.java
diff --git a/src/main/java/io/jsonwebtoken/lang/Objects.java b/api/src/main/java/io/jsonwebtoken/lang/Objects.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/lang/Objects.java
rename to api/src/main/java/io/jsonwebtoken/lang/Objects.java
index eb475ac6..4960b735 100644
--- a/src/main/java/io/jsonwebtoken/lang/Objects.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Objects.java
@@ -22,10 +22,7 @@ import java.util.Arrays;
public final class Objects {
- //for code coverage
- private static final Objects INSTANCE = new Objects();
-
- private Objects(){}
+ private Objects(){} //prevent instantiation
private static final int INITIAL_HASH = 7;
private static final int MULTIPLIER = 31;
diff --git a/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java b/api/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java
similarity index 92%
rename from src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java
rename to api/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java
index eb71e4a6..df5b8c7c 100644
--- a/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java
@@ -21,9 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public final class RuntimeEnvironment {
- private static final RuntimeEnvironment INSTANCE = new RuntimeEnvironment();
-
- private RuntimeEnvironment(){}
+ private RuntimeEnvironment(){} //prevent instantiation
private static final String BC_PROVIDER_CLASS_NAME = "org.bouncycastle.jce.provider.BouncyCastleProvider";
@@ -33,7 +31,7 @@ public final class RuntimeEnvironment {
public static void enableBouncyCastleIfPossible() {
- if (bcLoaded.get()) {
+ if (!BOUNCY_CASTLE_AVAILABLE || bcLoaded.get()) {
return;
}
diff --git a/src/main/java/io/jsonwebtoken/lang/Strings.java b/api/src/main/java/io/jsonwebtoken/lang/Strings.java
similarity index 99%
rename from src/main/java/io/jsonwebtoken/lang/Strings.java
rename to api/src/main/java/io/jsonwebtoken/lang/Strings.java
index 338803f9..065bb251 100644
--- a/src/main/java/io/jsonwebtoken/lang/Strings.java
+++ b/api/src/main/java/io/jsonwebtoken/lang/Strings.java
@@ -31,8 +31,6 @@ import java.util.TreeSet;
public final class Strings {
- private static final Strings INSTANCE = new Strings(); //for code coverage
-
private static final String FOLDER_SEPARATOR = "/";
private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
@@ -45,7 +43,7 @@ public final class Strings {
public static final Charset UTF_8 = Charset.forName("UTF-8");
- private Strings(){}
+ private Strings(){} //prevent instantiation
//---------------------------------------------------------------------
// General convenience methods for working with Strings
diff --git a/src/main/java/io/jsonwebtoken/lang/UnknownClassException.java b/api/src/main/java/io/jsonwebtoken/lang/UnknownClassException.java
similarity index 100%
rename from src/main/java/io/jsonwebtoken/lang/UnknownClassException.java
rename to api/src/main/java/io/jsonwebtoken/lang/UnknownClassException.java
diff --git a/api/src/test/groovy/io/jsonwebtoken/CompressionCodecsTest.groovy b/api/src/test/groovy/io/jsonwebtoken/CompressionCodecsTest.groovy
new file mode 100644
index 00000000..fa018280
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/CompressionCodecsTest.groovy
@@ -0,0 +1,42 @@
+package io.jsonwebtoken
+
+import io.jsonwebtoken.lang.Classes
+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.createMock
+import static org.easymock.EasyMock.eq
+import static org.easymock.EasyMock.expect
+import static org.junit.Assert.assertSame
+import static org.powermock.api.easymock.PowerMock.mockStatic
+import static org.powermock.api.easymock.PowerMock.replay
+import static org.powermock.api.easymock.PowerMock.verify
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest([Classes, CompressionCodecs])
+class CompressionCodecsTest {
+
+ @Test
+ void testStatics() {
+
+ mockStatic(Classes)
+
+ def deflate = createMock(CompressionCodec)
+ def gzip = createMock(CompressionCodec)
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.compression.DeflateCompressionCodec"))).andReturn(deflate)
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.compression.GzipCompressionCodec"))).andReturn(gzip)
+
+ replay Classes, deflate, gzip
+
+ assertSame deflate, CompressionCodecs.DEFLATE
+ assertSame gzip, CompressionCodecs.GZIP
+
+ verify Classes, deflate, gzip
+
+ //test coverage for private constructor:
+ new CompressionCodecs()
+ }
+}
diff --git a/src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy
similarity index 96%
rename from src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy
index f588ebbd..49cb371a 100644
--- a/src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/CompressionExceptionTest.groovy
@@ -19,22 +19,18 @@ import org.junit.Test
import static org.junit.Assert.assertEquals
-class CompressionExceptionTest {
+class CompressionExceptionTest {
@Test
void testDefaultConstructor() {
def exception = new CompressionException("my message")
-
assertEquals "my message", exception.getMessage()
}
@Test
void testConstructorWithCause() {
-
def ioException = new IOException("root error")
-
def exception = new CompressionException("wrapping", ioException)
-
assertEquals "wrapping", exception.getMessage()
assertEquals ioException, exception.getCause()
}
diff --git a/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy
similarity index 64%
rename from src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy
index 32898b7b..8c8065d3 100644
--- a/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/ExpiredJwtExceptionTest.groovy
@@ -16,19 +16,42 @@
package io.jsonwebtoken
import org.junit.Test
+
+import static org.easymock.EasyMock.*
import static org.junit.Assert.*
class ExpiredJwtExceptionTest {
+ @Test
+ void testStringConstructor() {
+ def header = createMock(Header)
+ def claims = createMock(Claims)
+ def msg = 'foo'
+
+ replay header, claims
+
+ def ex = new ExpiredJwtException(header, claims, msg)
+
+ verify header, claims
+
+ assertSame ex.header, header
+ assertSame ex.claims, claims
+ assertEquals ex.message, msg
+ }
+
@Test
void testOverloadedConstructor() {
- def header = Jwts.header()
- def claims = Jwts.claims()
+ def header = createMock(Header)
+ def claims = createMock(Claims)
def msg = 'foo'
def cause = new NullPointerException()
+ replay header, claims
+
def ex = new ExpiredJwtException(header, claims, msg, cause)
+ verify header, claims
+
assertSame ex.header, header
assertSame ex.claims, claims
assertEquals ex.message, msg
diff --git a/src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy
similarity index 62%
rename from src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy
index 3a3062ab..664462b7 100644
--- a/src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/IncorrectClaimExceptionTest.groovy
@@ -17,25 +17,54 @@ package io.jsonwebtoken
import org.junit.Test
+import static org.easymock.EasyMock.*
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertSame
class IncorrectClaimExceptionTest {
+ @Test
+ void testStringConstructor() {
+ def header = createMock(Header)
+ def claims = createMock(Claims)
+ def msg = 'foo'
+
+ def claimName = 'cName'
+ def claimValue = 'cValue'
+
+ replay header, claims
+
+ def ex = new IncorrectClaimException(header, claims, msg)
+ ex.setClaimName(claimName)
+ ex.setClaimValue(claimValue)
+
+ verify header, claims
+
+ assertSame ex.header, header
+ assertSame ex.claims, claims
+ assertEquals ex.message, msg
+ assertEquals ex.claimName, claimName
+ assertEquals ex.claimValue, claimValue
+ }
+
@Test
void testOverloadedConstructor() {
- def header = Jwts.header()
- def claims = Jwts.claims()
+ def header = createMock(Header)
+ def claims = createMock(Claims)
def msg = 'foo'
def cause = new NullPointerException()
def claimName = 'cName'
def claimValue = 'cValue'
+ replay header, claims
+
def ex = new IncorrectClaimException(header, claims, msg, cause)
ex.setClaimName(claimName)
ex.setClaimValue(claimValue)
+ verify header, claims
+
assertSame ex.header, header
assertSame ex.claims, claims
assertEquals ex.message, msg
diff --git a/src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy
similarity index 88%
rename from src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy
index 5209a041..5fbcf6e7 100644
--- a/src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/InvalidClaimExceptionTest.groovy
@@ -17,6 +17,7 @@ package io.jsonwebtoken
import org.junit.Test
+import static org.easymock.EasyMock.*
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertSame
@@ -24,18 +25,22 @@ class InvalidClaimExceptionTest {
@Test
void testOverloadedConstructor() {
- def header = Jwts.header()
- def claims = Jwts.claims()
+ def header = createMock(Header)
+ def claims = createMock(Claims)
def msg = 'foo'
def cause = new NullPointerException()
def claimName = 'cName'
def claimValue = 'cValue'
+ replay header, claims
+
def ex = new InvalidClaimException(header, claims, msg, cause)
ex.setClaimName(claimName)
ex.setClaimValue(claimValue)
+ verify header, claims
+
assertSame ex.header, header
assertSame ex.claims, claims
assertEquals ex.message, msg
diff --git a/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy b/api/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy
similarity index 100%
rename from src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/JwtHandlerAdapterTest.groovy
diff --git a/api/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy b/api/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy
new file mode 100644
index 00000000..9b901622
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/JwtsTest.groovy
@@ -0,0 +1,182 @@
+package io.jsonwebtoken
+
+import io.jsonwebtoken.lang.Classes
+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.createMock
+import static org.easymock.EasyMock.eq
+import static org.easymock.EasyMock.expect
+import static org.easymock.EasyMock.same
+import static org.junit.Assert.assertSame
+import static org.powermock.api.easymock.PowerMock.mockStatic
+import static org.powermock.api.easymock.PowerMock.replay
+import static org.powermock.api.easymock.PowerMock.reset
+import static org.powermock.api.easymock.PowerMock.verify
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest([Classes, Jwts])
+class JwtsTest {
+
+ @Test
+ void testPrivateCtor() { //for code coverage only
+ new Jwts()
+ }
+
+ @Test
+ void testHeader() {
+
+ mockStatic(Classes)
+
+ def instance = createMock(Header)
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.DefaultHeader"))).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.header()
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testHeaderFromMap() {
+
+ mockStatic(Classes)
+
+ def map = [:]
+
+ def instance = createMock(Header)
+
+ expect(Classes.newInstance(
+ eq("io.jsonwebtoken.impl.DefaultHeader"),
+ same(Jwts.MAP_ARG),
+ same(map))
+ ).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.header(map)
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testJwsHeader() {
+
+ mockStatic(Classes)
+
+ def instance = createMock(JwsHeader)
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.DefaultJwsHeader"))).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.jwsHeader()
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testJwsHeaderFromMap() {
+
+ mockStatic(Classes)
+
+ def map = [:]
+
+ def instance = createMock(JwsHeader)
+
+ expect(Classes.newInstance(
+ eq("io.jsonwebtoken.impl.DefaultJwsHeader"),
+ same(Jwts.MAP_ARG),
+ same(map))
+ ).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.jwsHeader(map)
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testClaims() {
+
+ mockStatic(Classes)
+
+ def instance = createMock(Claims)
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.DefaultClaims"))).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.claims()
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testClaimsFromMap() {
+
+ mockStatic(Classes)
+
+ def map = [:]
+
+ def instance = createMock(Claims)
+
+ expect(Classes.newInstance(
+ eq("io.jsonwebtoken.impl.DefaultClaims"),
+ same(Jwts.MAP_ARG),
+ same(map))
+ ).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.claims(map)
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testParser() {
+
+ mockStatic(Classes)
+
+ def instance = createMock(JwtParser)
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.DefaultJwtParser"))).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.parser()
+
+ verify Classes, instance
+ }
+
+ @Test
+ void testBuilder() {
+
+ mockStatic(Classes)
+
+ //JwtBuilder loads SignatureAlgorithm which in turn uses RuntimeEnvironment which in turn checks for BC:
+ expect(Classes.isAvailable(eq("org.bouncycastle.jce.provider.BouncyCastleProvider"))).andReturn(false)
+
+ replay Classes
+
+ def instance = createMock(JwtBuilder)
+
+ verify Classes
+
+ reset Classes
+
+ expect(Classes.newInstance(eq("io.jsonwebtoken.impl.DefaultJwtBuilder"))).andReturn(instance)
+
+ replay Classes, instance
+
+ assertSame instance, Jwts.builder()
+
+ verify Classes, instance
+ }
+}
diff --git a/api/src/test/groovy/io/jsonwebtoken/MalformedJwtExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/MalformedJwtExceptionTest.groovy
new file mode 100644
index 00000000..d07c88ed
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/MalformedJwtExceptionTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken
+
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+
+class MalformedJwtExceptionTest {
+
+ @Test
+ void testStringConstructor() {
+ def exception = new MalformedJwtException("my message")
+ assertEquals "my message", exception.getMessage()
+ }
+
+ @Test
+ void testCauseConstructor() {
+ def ioException = new IOException("root error")
+ def exception = new MalformedJwtException("wrapping", ioException)
+ assertEquals "wrapping", exception.getMessage()
+ assertEquals ioException, exception.getCause()
+ }
+}
diff --git a/src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy
similarity index 62%
rename from src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy
index 36658df6..377eae15 100644
--- a/src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/MissingClaimExceptionTest.groovy
@@ -17,25 +17,54 @@ package io.jsonwebtoken
import org.junit.Test
+import static org.easymock.EasyMock.*
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertSame
class MissingClaimExceptionTest {
+ @Test
+ void testStringConstructor() {
+ def header = createMock(Header)
+ def claims = createMock(Claims)
+ def msg = 'foo'
+
+ def claimName = 'cName'
+ def claimValue = 'cValue'
+
+ replay header, claims
+
+ def ex = new MissingClaimException(header, claims, msg)
+ ex.setClaimName(claimName)
+ ex.setClaimValue(claimValue)
+
+ verify header, claims
+
+ assertSame ex.header, header
+ assertSame ex.claims, claims
+ assertEquals ex.message, msg
+ assertEquals ex.claimName, claimName
+ assertEquals ex.claimValue, claimValue
+ }
+
@Test
void testOverloadedConstructor() {
- def header = Jwts.header()
- def claims = Jwts.claims()
+ def header = createMock(Header)
+ def claims = createMock(Claims)
def msg = 'foo'
def cause = new NullPointerException()
def claimName = 'cName'
def claimValue = 'cValue'
+ replay header, claims
+
def ex = new MissingClaimException(header, claims, msg, cause)
ex.setClaimName(claimName)
ex.setClaimValue(claimValue)
+ verify header, claims
+
assertSame ex.header, header
assertSame ex.claims, claims
assertEquals ex.message, msg
diff --git a/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy
similarity index 64%
rename from src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy
index 77bf0e1a..74859255 100644
--- a/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/PrematureJwtExceptionTest.groovy
@@ -16,19 +16,42 @@
package io.jsonwebtoken
import org.junit.Test
+
+import static org.easymock.EasyMock.*
import static org.junit.Assert.*
class PrematureJwtExceptionTest {
+ @Test
+ void testStringConstructor() {
+ def header = createMock(Header)
+ def claims = createMock(Claims)
+ def msg = 'foo'
+
+ replay header, claims
+
+ def ex = new PrematureJwtException(header, claims, msg)
+
+ verify header, claims
+
+ assertSame ex.header, header
+ assertSame ex.claims, claims
+ assertEquals ex.message, msg
+ }
+
@Test
void testOverloadedConstructor() {
- def header = Jwts.header()
- def claims = Jwts.claims()
+ def header = createMock(Header)
+ def claims = createMock(Claims)
def msg = 'foo'
def cause = new NullPointerException()
+ replay header, claims
+
def ex = new PrematureJwtException(header, claims, msg, cause)
+ verify header, claims
+
assertSame ex.header, header
assertSame ex.claims, claims
assertEquals ex.message, msg
diff --git a/src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy
similarity index 72%
rename from src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy
index dded945d..e82ff670 100644
--- a/src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/RequiredTypeExceptionTest.groovy
@@ -6,15 +6,20 @@ import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertSame
class RequiredTypeExceptionTest {
+
+ @Test
+ void testStringConstructor() {
+ def msg = 'foo'
+ def ex = new RequiredTypeException(msg)
+ assertEquals ex.message, msg
+ }
+
@Test
void testOverloadedConstructor() {
def msg = 'foo'
def cause = new NullPointerException()
-
def ex = new RequiredTypeException(msg, cause)
-
assertEquals ex.message, msg
assertSame ex.cause, cause
}
-
}
diff --git a/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy b/api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy
similarity index 100%
rename from src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy
diff --git a/api/src/test/groovy/io/jsonwebtoken/SignatureExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/SignatureExceptionTest.groovy
new file mode 100644
index 00000000..fa04b3b2
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/SignatureExceptionTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken
+
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+
+class SignatureExceptionTest {
+
+ @Test
+ void testStringConstructor() {
+ def exception = new SignatureException("my message")
+ assertEquals "my message", exception.getMessage()
+ }
+
+ @Test
+ void testCauseConstructor() {
+ def ioException = new IOException("root error")
+ def exception = new SignatureException("wrapping", ioException)
+ assertEquals "wrapping", exception.getMessage()
+ assertEquals ioException, exception.getCause()
+ }
+}
diff --git a/api/src/test/groovy/io/jsonwebtoken/SigningKeyResolverAdapterTest.groovy b/api/src/test/groovy/io/jsonwebtoken/SigningKeyResolverAdapterTest.groovy
new file mode 100644
index 00000000..a1c58882
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/SigningKeyResolverAdapterTest.groovy
@@ -0,0 +1,102 @@
+package io.jsonwebtoken
+
+import org.junit.Test
+
+import javax.crypto.spec.SecretKeySpec
+
+import static org.easymock.EasyMock.*
+import static org.junit.Assert.*
+
+class SigningKeyResolverAdapterTest {
+
+ @Test(expected=UnsupportedJwtException) //should throw since called but not overridden
+ void testDefaultResolveSigningKeyBytesFromClaims() {
+ def header = createMock(JwsHeader)
+ def claims = createMock(Claims)
+ new SigningKeyResolverAdapter().resolveSigningKeyBytes(header, claims)
+ }
+
+ @Test(expected=UnsupportedJwtException) //should throw since called but not overridden
+ void testDefaultResolveSigningKeyBytesFromStringPayload() {
+ def header = createMock(JwsHeader)
+ new SigningKeyResolverAdapter().resolveSigningKeyBytes(header, "hi")
+ }
+
+ @Test
+ void testResolveSigningKeyHmac() {
+
+ JwsHeader header = createMock(JwsHeader)
+ Claims claims = createMock(Claims)
+
+ byte[] bytes = new byte[32]
+ new Random().nextBytes(bytes)
+
+ expect(header.getAlgorithm()).andReturn("HS256")
+
+ replay header, claims
+
+ def adapter = new SigningKeyResolverAdapter() {
+ @Override
+ byte[] resolveSigningKeyBytes(JwsHeader h, Claims c) {
+ assertSame header, h
+ assertSame claims, c
+ return bytes
+ }
+ }
+
+ def key = adapter.resolveSigningKey(header, claims)
+
+ verify header, claims
+
+ assertTrue key instanceof SecretKeySpec
+ assertEquals 'HmacSHA256', key.algorithm
+ assertTrue Arrays.equals(bytes, key.encoded)
+ }
+
+ @Test(expected=IllegalArgumentException)
+ void testResolveSigningKeyDefaultWithoutHmac() {
+ JwsHeader header = createMock(JwsHeader)
+ Claims claims = createMock(Claims)
+ expect(header.getAlgorithm()).andReturn("RS256")
+ replay header, claims
+ new SigningKeyResolverAdapter().resolveSigningKey(header, claims)
+ }
+
+ @Test
+ void testResolveSigningKeyPayloadHmac() {
+
+ JwsHeader header = createMock(JwsHeader)
+
+ byte[] bytes = new byte[32]
+ new Random().nextBytes(bytes)
+
+ expect(header.getAlgorithm()).andReturn("HS256")
+
+ replay header
+
+ def adapter = new SigningKeyResolverAdapter() {
+ @Override
+ byte[] resolveSigningKeyBytes(JwsHeader h, String s) {
+ assertSame header, h
+ assertEquals 'hi', s
+ return bytes
+ }
+ }
+
+ def key = adapter.resolveSigningKey(header, 'hi')
+
+ verify header
+
+ assertTrue key instanceof SecretKeySpec
+ assertEquals 'HmacSHA256', key.algorithm
+ assertTrue Arrays.equals(bytes, key.encoded)
+ }
+
+ @Test(expected=IllegalArgumentException)
+ void testResolveSigningKeyPayloadWithoutHmac() {
+ JwsHeader header = createMock(JwsHeader)
+ expect(header.getAlgorithm()).andReturn("RS256")
+ replay header
+ new SigningKeyResolverAdapter().resolveSigningKey(header, 'hi')
+ }
+}
diff --git a/api/src/test/groovy/io/jsonwebtoken/UnsupportedJwtExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/UnsupportedJwtExceptionTest.groovy
new file mode 100644
index 00000000..b4fde5e2
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/UnsupportedJwtExceptionTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken
+
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+
+class UnsupportedJwtExceptionTest {
+
+ @Test
+ void testStringConstructor() {
+ def exception = new UnsupportedJwtException("my message")
+ assertEquals "my message", exception.getMessage()
+ }
+
+ @Test
+ void testCauseConstructor() {
+ def ioException = new IOException("root error")
+ def exception = new UnsupportedJwtException("wrapping", ioException)
+ assertEquals "wrapping", exception.getMessage()
+ assertEquals ioException, exception.getCause()
+ }
+}
diff --git a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64DecoderTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/Base64DecoderTest.groovy
similarity index 93%
rename from src/test/groovy/io/jsonwebtoken/codec/impl/Base64DecoderTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/Base64DecoderTest.groovy
index 307a8e37..81a2b11d 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64DecoderTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/Base64DecoderTest.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec.impl
+package io.jsonwebtoken.io
import io.jsonwebtoken.lang.Strings
import org.junit.Test
diff --git a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64EncoderTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/Base64EncoderTest.groovy
similarity index 93%
rename from src/test/groovy/io/jsonwebtoken/codec/impl/Base64EncoderTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/Base64EncoderTest.groovy
index b1b54485..fe4fc9b2 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64EncoderTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/Base64EncoderTest.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec.impl
+package io.jsonwebtoken.io
import io.jsonwebtoken.lang.Strings
import org.junit.Test
diff --git a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64Test.groovy b/api/src/test/groovy/io/jsonwebtoken/io/Base64Test.groovy
similarity index 71%
rename from src/test/groovy/io/jsonwebtoken/codec/impl/Base64Test.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/Base64Test.groovy
index 1a584570..aac5f2e8 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/impl/Base64Test.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/Base64Test.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec.impl
+package io.jsonwebtoken.io
import io.jsonwebtoken.lang.Strings
import org.junit.Test
@@ -82,60 +82,86 @@ class Base64Test {
assertEquals PLAINTEXT, new String(resultBytes, Strings.UTF_8)
}
- private static String BASE64(String s) {
+ private static String encode(String s) {
byte[] bytes = s.getBytes(Strings.UTF_8);
return Base64.DEFAULT.encodeToString(bytes, false)
}
+ private static String decode(String s) {
+ byte[] bytes = Base64.DEFAULT.decodeFast(s.toCharArray())
+ return new String(bytes, Strings.UTF_8)
+ }
+
@Test // https://tools.ietf.org/html/rfc4648#page-12
void testRfc4648Base64TestVectors() {
- assertEquals "", BASE64("")
+ assertEquals "", encode("")
+ assertEquals "", decode("")
- assertEquals "Zg==", BASE64("f")
+ assertEquals "Zg==", encode("f")
+ assertEquals "f", decode("Zg==")
- assertEquals "Zm8=", BASE64("fo")
+ assertEquals "Zm8=", encode("fo")
+ assertEquals "fo", decode("Zm8=")
- assertEquals "Zm9v", BASE64("foo")
+ assertEquals "Zm9v", encode("foo")
+ assertEquals "foo", decode("Zm9v")
- assertEquals "Zm9vYg==", BASE64("foob")
+ assertEquals "Zm9vYg==", encode("foob")
+ assertEquals "foob", decode("Zm9vYg==")
- assertEquals "Zm9vYmE=", BASE64("fooba")
+ assertEquals "Zm9vYmE=", encode("fooba")
+ assertEquals "fooba", decode("Zm9vYmE=")
- assertEquals "Zm9vYmFy", BASE64("foobar")
+ assertEquals "Zm9vYmFy", encode("foobar")
+ assertEquals "foobar", decode("Zm9vYmFy")
def input = 'special: [\r\n \t], ascii[32..126]: [ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~]\n'
def expected = "c3BlY2lhbDogWw0KIAldLCBhc2NpaVszMi4uMTI2XTogWyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+XQo="
- assertEquals expected, BASE64(input)
+ assertEquals expected, encode(input)
+ assertEquals input, decode(expected)
}
- private static String BASE64URL(String s) {
+ private static String urlEncode(String s) {
byte[] bytes = s.getBytes(Strings.UTF_8);
return Base64.URL_SAFE.encodeToString(bytes, false)
}
+ private static String urlDecode(String s) {
+ byte[] bytes = Base64.URL_SAFE.decodeFast(s.toCharArray())
+ return new String(bytes, Strings.UTF_8)
+ }
+
@Test //same test vectors above, but with padding removed & some specials swapped: https://brockallen.com/2014/10/17/base64url-encoding/
void testRfc4648Base64UrlTestVectors() {
- assertEquals "", BASE64URL("")
+ assertEquals "", urlEncode("")
+ assertEquals "", urlDecode("")
- assertEquals "Zg", BASE64URL("f") //base64 = 2 padding chars, base64url = no padding needed
+ assertEquals "Zg", urlEncode("f") //base64 = 2 padding chars, base64url = no padding needed
+ assertEquals "f", urlDecode("Zg")
- assertEquals "Zm8", BASE64URL("fo") //base64 = 1 padding char, base64url = no padding needed
+ assertEquals "Zm8", urlEncode("fo") //base64 = 1 padding char, base64url = no padding needed
+ assertEquals "fo", urlDecode("Zm8")
- assertEquals "Zm9v", BASE64URL("foo")
+ assertEquals "Zm9v", urlEncode("foo")
+ assertEquals "foo", urlDecode("Zm9v")
- assertEquals "Zm9vYg", BASE64URL("foob") //base64 = 2 padding chars, base64url = no padding needed
+ assertEquals "Zm9vYg", urlEncode("foob") //base64 = 2 padding chars, base64url = no padding needed
+ assertEquals "foob", urlDecode("Zm9vYg")
- assertEquals "Zm9vYmE", BASE64URL("fooba") //base64 = 1 padding char, base64url = no padding needed
+ assertEquals "Zm9vYmE", urlEncode("fooba") //base64 = 1 padding char, base64url = no padding needed
+ assertEquals "fooba", urlDecode("Zm9vYmE")
- assertEquals "Zm9vYmFy", BASE64URL("foobar")
+ assertEquals "Zm9vYmFy", urlEncode("foobar")
+ assertEquals "foobar", urlDecode("Zm9vYmFy")
def input = 'special: [\r\n \t], ascii[32..126]: [ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~]\n'
def expected = "c3BlY2lhbDogWw0KIAldLCBhc2NpaVszMi4uMTI2XTogWyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+XQo="
.replace("=", "")
.replace("+", "-")
.replace("/", "_")
- assertEquals expected, BASE64URL(input)
+ assertEquals expected, urlEncode(input)
+ assertEquals input, urlDecode(expected)
}
}
diff --git a/src/test/groovy/io/jsonwebtoken/codec/CodecExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/CodecExceptionTest.groovy
similarity index 78%
rename from src/test/groovy/io/jsonwebtoken/codec/CodecExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/CodecExceptionTest.groovy
index 07151036..92d686e6 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/CodecExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/CodecExceptionTest.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec
+package io.jsonwebtoken.io
import org.junit.Test
@@ -8,7 +8,7 @@ class CodecExceptionTest {
@Test
void testConstructorWithCause() {
- def ioException = new IOException("root error")
+ def ioException = new java.io.IOException("root error")
def exception = new CodecException("wrapping", ioException)
assertEquals "wrapping", exception.getMessage()
assertEquals ioException, exception.getCause()
diff --git a/api/src/test/groovy/io/jsonwebtoken/io/DecodersTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/DecodersTest.groovy
new file mode 100644
index 00000000..1f953c1b
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/io/DecodersTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken.io
+
+import org.junit.Test
+
+import static org.junit.Assert.*
+
+class DecodersTest {
+
+ @Test
+ void testBase64() {
+ new Decoders() //not allowed in java, including here only to pass test coverage assertions
+ assertTrue Decoders.BASE64 instanceof ExceptionPropagatingDecoder
+ assertTrue Decoders.BASE64.decoder instanceof Base64Decoder
+ }
+
+ @Test
+ void testBase64Url() {
+ assertTrue Decoders.BASE64URL instanceof ExceptionPropagatingDecoder
+ assertTrue Decoders.BASE64URL.decoder instanceof Base64UrlDecoder
+ }
+
+}
diff --git a/src/test/groovy/io/jsonwebtoken/codec/DecodingExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/DecodingExceptionTest.groovy
similarity index 78%
rename from src/test/groovy/io/jsonwebtoken/codec/DecodingExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/DecodingExceptionTest.groovy
index 99c21862..38a85647 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/DecodingExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/DecodingExceptionTest.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec
+package io.jsonwebtoken.io
import org.junit.Test
@@ -8,7 +8,7 @@ class DecodingExceptionTest {
@Test
void testConstructorWithCause() {
- def ioException = new IOException("root error")
+ def ioException = new java.io.IOException("root error")
def exception = new DecodingException("wrapping", ioException)
assertEquals "wrapping", exception.getMessage()
assertEquals ioException, exception.getCause()
diff --git a/api/src/test/groovy/io/jsonwebtoken/io/DeserializationExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/DeserializationExceptionTest.groovy
new file mode 100644
index 00000000..ded8484c
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/io/DeserializationExceptionTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken.io
+
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+
+class DeserializationExceptionTest {
+
+ @Test
+ void testDefaultConstructor() {
+ def exception = new DeserializationException("my message")
+ assertEquals "my message", exception.getMessage()
+ }
+
+ @Test
+ void testConstructorWithCause() {
+ def ioException = new java.io.IOException("root error")
+ def exception = new DeserializationException("wrapping", ioException)
+ assertEquals "wrapping", exception.getMessage()
+ assertEquals ioException, exception.getCause()
+ }
+}
diff --git a/api/src/test/groovy/io/jsonwebtoken/io/EncodersTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/EncodersTest.groovy
new file mode 100644
index 00000000..fc4acfd1
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/io/EncodersTest.groovy
@@ -0,0 +1,21 @@
+package io.jsonwebtoken.io
+
+import org.junit.Test
+
+import static org.junit.Assert.*
+
+class EncodersTest {
+
+ @Test
+ void testBase64() {
+ new Encoders() //not allowed in java, including here only to pass test coverage assertions
+ assertTrue Encoders.BASE64 instanceof ExceptionPropagatingEncoder
+ assertTrue Encoders.BASE64.encoder instanceof Base64Encoder
+ }
+
+ @Test
+ void testBase64Url() {
+ assertTrue Encoders.BASE64URL instanceof ExceptionPropagatingEncoder
+ assertTrue Encoders.BASE64URL.encoder instanceof Base64UrlEncoder
+ }
+}
diff --git a/src/test/groovy/io/jsonwebtoken/codec/EncodingExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/EncodingExceptionTest.groovy
similarity index 78%
rename from src/test/groovy/io/jsonwebtoken/codec/EncodingExceptionTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/EncodingExceptionTest.groovy
index 8d68928c..f4fbbd3a 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/EncodingExceptionTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/EncodingExceptionTest.groovy
@@ -1,4 +1,4 @@
-package io.jsonwebtoken.codec
+package io.jsonwebtoken.io
import org.junit.Test
@@ -8,7 +8,7 @@ class EncodingExceptionTest {
@Test
void testConstructorWithCause() {
- def ioException = new IOException("root error")
+ def ioException = new java.io.IOException("root error")
def exception = new EncodingException("wrapping", ioException)
assertEquals "wrapping", exception.getMessage()
assertEquals ioException, exception.getCause()
diff --git a/src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoderTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingDecoderTest.groovy
similarity index 85%
rename from src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoderTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingDecoderTest.groovy
index 3d3a0da9..8268e8f0 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingDecoderTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingDecoderTest.groovy
@@ -1,8 +1,5 @@
-package io.jsonwebtoken.codec.impl
+package io.jsonwebtoken.io
-import io.jsonwebtoken.codec.Decoder
-import io.jsonwebtoken.codec.DecodingException
-import io.jsonwebtoken.codec.EncodingException
import org.junit.Test
import static org.junit.Assert.*
@@ -25,7 +22,7 @@ class ExceptionPropagatingDecoderTest {
def decoder = new ExceptionPropagatingDecoder(new Decoder() {
@Override
Object decode(Object o) throws DecodingException {
- throw new DecodingException("problem", new IOException("dummy"))
+ throw new DecodingException("problem", new java.io.IOException("dummy"))
}
})
try {
diff --git a/src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoderTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingEncoderTest.groovy
similarity index 88%
rename from src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoderTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingEncoderTest.groovy
index 625a5e9c..965115a9 100644
--- a/src/test/groovy/io/jsonwebtoken/codec/impl/ExceptionPropagatingEncoderTest.groovy
+++ b/api/src/test/groovy/io/jsonwebtoken/io/ExceptionPropagatingEncoderTest.groovy
@@ -1,7 +1,5 @@
-package io.jsonwebtoken.codec.impl
+package io.jsonwebtoken.io
-import io.jsonwebtoken.codec.Encoder
-import io.jsonwebtoken.codec.EncodingException
import org.junit.Test
import static org.junit.Assert.*
@@ -25,7 +23,7 @@ class ExceptionPropagatingEncoderTest {
def encoder = new ExceptionPropagatingEncoder(new Encoder() {
@Override
Object encode(Object o) throws EncodingException {
- throw new EncodingException("problem", new IOException("dummy"))
+ throw new EncodingException("problem", new java.io.IOException("dummy"))
}
})
try {
diff --git a/api/src/test/groovy/io/jsonwebtoken/io/SerializationExceptionTest.groovy b/api/src/test/groovy/io/jsonwebtoken/io/SerializationExceptionTest.groovy
new file mode 100644
index 00000000..1709e2ec
--- /dev/null
+++ b/api/src/test/groovy/io/jsonwebtoken/io/SerializationExceptionTest.groovy
@@ -0,0 +1,22 @@
+package io.jsonwebtoken.io
+
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+
+class SerializationExceptionTest {
+
+ @Test
+ void testDefaultConstructor() {
+ def exception = new SerializationException("my message")
+ assertEquals "my message", exception.getMessage()
+ }
+
+ @Test
+ void testConstructorWithCause() {
+ def ioException = new java.io.IOException("root error")
+ def exception = new SerializationException("wrapping", ioException)
+ assertEquals "wrapping", exception.getMessage()
+ assertEquals ioException, exception.getCause()
+ }
+}
diff --git a/src/test/groovy/io/jsonwebtoken/lang/StringsTest.groovy b/api/src/test/groovy/io/jsonwebtoken/lang/StringsTest.groovy
similarity index 100%
rename from src/test/groovy/io/jsonwebtoken/lang/StringsTest.groovy
rename to api/src/test/groovy/io/jsonwebtoken/lang/StringsTest.groovy
diff --git a/core/pom.xml b/core/pom.xml
new file mode 100644
index 00000000..d20798aa
--- /dev/null
+++ b/core/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ 4.0.0
+
+
+ io.jsonwebtoken
+ jjwt-root
+ 0.10.0-SNAPSHOT
+ ../pom.xml
+
+
+ jjwt-core
+ JJWT :: Core
+ jar
+
+
+ ${basedir}/..
+
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+
+
+ io.jsonwebtoken
+ jjwt-impl
+ runtime
+
+
+
+
\ No newline at end of file
diff --git a/extensions/jackson/pom.xml b/extensions/jackson/pom.xml
new file mode 100644
index 00000000..c6c9ef73
--- /dev/null
+++ b/extensions/jackson/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+
+ 4.0.0
+
+
+ io.jsonwebtoken
+ jjwt-root
+ 0.10.0-SNAPSHOT
+ ../../pom.xml
+
+
+ jjwt-jackson
+ JJWT :: Extensions :: Jackson
+ jar
+
+
+ ${basedir}/../..
+
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonDeserializer.java b/extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonDeserializer.java
similarity index 83%
rename from src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonDeserializer.java
rename to extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonDeserializer.java
index f236b655..c9dd9e07 100644
--- a/src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonDeserializer.java
+++ b/extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonDeserializer.java
@@ -1,14 +1,13 @@
-package io.jsonwebtoken.io.impl.jackson;
+package io.jsonwebtoken.io;
import com.fasterxml.jackson.databind.ObjectMapper;
-import io.jsonwebtoken.io.DeserializationException;
-import io.jsonwebtoken.io.Deserializer;
import io.jsonwebtoken.lang.Assert;
import java.io.IOException;
-import java.util.Map;
-@SuppressWarnings("unused") //used via reflection by RuntimeClasspathDeserializerLocator
+/**
+ * @since 0.10.0
+ */
public class JacksonDeserializer implements Deserializer {
private final Class returnType;
@@ -21,7 +20,7 @@ public class JacksonDeserializer implements Deserializer {
@SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) // for end-users providing a custom ObjectMapper
public JacksonDeserializer(ObjectMapper objectMapper) {
- this(objectMapper, (Class) Map.class);
+ this(objectMapper, (Class) Object.class);
}
private JacksonDeserializer(ObjectMapper objectMapper, Class returnType) {
diff --git a/src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonSerializer.java b/extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonSerializer.java
similarity index 91%
rename from src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonSerializer.java
rename to extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonSerializer.java
index 756f6fff..04650188 100644
--- a/src/main/java/io/jsonwebtoken/io/impl/jackson/JacksonSerializer.java
+++ b/extensions/jackson/src/main/java/io/jsonwebtoken/io/JacksonSerializer.java
@@ -1,11 +1,12 @@
-package io.jsonwebtoken.io.impl.jackson;
+package io.jsonwebtoken.io;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import io.jsonwebtoken.io.SerializationException;
-import io.jsonwebtoken.io.Serializer;
import io.jsonwebtoken.lang.Assert;
+/**
+ * @since 0.10.0
+ */
public class JacksonSerializer implements Serializer {
static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper();
diff --git a/src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonDeserializerTest.groovy b/extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonDeserializerTest.groovy
similarity index 78%
rename from src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonDeserializerTest.groovy
rename to extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonDeserializerTest.groovy
index 503a0c9a..cfb23c95 100644
--- a/src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonDeserializerTest.groovy
+++ b/extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonDeserializerTest.groovy
@@ -1,14 +1,10 @@
-package io.jsonwebtoken.io.impl.jackson
+package io.jsonwebtoken.io
import com.fasterxml.jackson.databind.ObjectMapper
-import io.jsonwebtoken.io.DeserializationException
import io.jsonwebtoken.lang.Strings
import org.junit.Test
-import static org.easymock.EasyMock.createMock
-import static org.easymock.EasyMock.expect
-import static org.easymock.EasyMock.replay
-import static org.easymock.EasyMock.verify
+import static org.easymock.EasyMock.*
import static org.junit.Assert.*
class JacksonDeserializerTest {
@@ -42,13 +38,13 @@ class JacksonDeserializerTest {
@Test
void testDeserializeFailsWithJsonProcessingException() {
- def ex = createMock(IOException)
+ def ex = createMock(java.io.IOException)
expect(ex.getMessage()).andReturn('foo')
def deserializer = new JacksonDeserializer() {
@Override
- protected Object readValue(byte[] bytes) throws IOException {
+ protected Object readValue(byte[] bytes) throws java.io.IOException {
throw ex
}
}
@@ -59,7 +55,7 @@ class JacksonDeserializerTest {
deserializer.deserialize('{"hello":"世界"}'.getBytes(Strings.UTF_8))
fail()
} catch (DeserializationException se) {
- assertEquals 'Unable to deserialize bytes into a java.util.Map instance: foo', se.getMessage()
+ assertEquals 'Unable to deserialize bytes into a java.lang.Object instance: foo', se.getMessage()
assertSame ex, se.getCause()
}
diff --git a/src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonSerializerTest.groovy b/extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonSerializerTest.groovy
similarity index 83%
rename from src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonSerializerTest.groovy
rename to extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonSerializerTest.groovy
index d2abe3ce..08f70ee6 100644
--- a/src/test/groovy/io/jsonwebtoken/io/impl/jackson/JacksonSerializerTest.groovy
+++ b/extensions/jackson/src/test/groovy/io/jsonwebtoken/io/JacksonSerializerTest.groovy
@@ -1,16 +1,11 @@
-package io.jsonwebtoken.io.impl.jackson
+package io.jsonwebtoken.io
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
-import io.jsonwebtoken.codec.Encoder
-import io.jsonwebtoken.io.SerializationException
import io.jsonwebtoken.lang.Strings
import org.junit.Test
-import static org.easymock.EasyMock.createMock
-import static org.easymock.EasyMock.expect
-import static org.easymock.EasyMock.replay
-import static org.easymock.EasyMock.verify
+import static org.easymock.EasyMock.*
import static org.junit.Assert.*
class JacksonSerializerTest {
@@ -44,8 +39,7 @@ class JacksonSerializerTest {
@Test
void testByteArray() { //expect Base64 string by default:
byte[] bytes = "hi".getBytes(Strings.UTF_8)
- String encoded = Encoder.BASE64.encode(bytes)
- String expected = "\"$encoded\"" as String
+ String expected = '"aGk="' as String //base64(hi) --> aGk=
byte[] result = new JacksonSerializer().serialize(bytes)
assertEquals expected, new String(result, Strings.UTF_8)
}
@@ -53,10 +47,8 @@ class JacksonSerializerTest {
@Test
void testEmptyByteArray() { //expect Base64 string by default:
byte[] bytes = new byte[0]
- String encoded = Encoder.BASE64.encode(bytes)
- String expected = "\"$encoded\"" as String
byte[] result = new JacksonSerializer().serialize(bytes)
- assertEquals expected, new String(result, Strings.UTF_8)
+ assertEquals '""', new String(result, Strings.UTF_8)
}
@Test
diff --git a/extensions/orgjson/pom.xml b/extensions/orgjson/pom.xml
new file mode 100644
index 00000000..05bab69b
--- /dev/null
+++ b/extensions/orgjson/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+
+ 4.0.0
+
+
+ io.jsonwebtoken
+ jjwt-root
+ 0.10.0-SNAPSHOT
+ ../../pom.xml
+
+
+ jjwt-orgjson
+ JJWT :: Extensions :: org.json
+ jar
+
+
+ ${basedir}/../..
+
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+
+
+ org.json
+ json
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/jsonwebtoken/io/impl/orgjson/OrgJsonDeserializer.java b/extensions/orgjson/src/main/java/io/jsonwebtoken/io/OrgJsonDeserializer.java
similarity index 94%
rename from src/main/java/io/jsonwebtoken/io/impl/orgjson/OrgJsonDeserializer.java
rename to extensions/orgjson/src/main/java/io/jsonwebtoken/io/OrgJsonDeserializer.java
index 909ff307..bd8e7068 100644
--- a/src/main/java/io/jsonwebtoken/io/impl/orgjson/OrgJsonDeserializer.java
+++ b/extensions/orgjson/src/main/java/io/jsonwebtoken/io/OrgJsonDeserializer.java
@@ -1,7 +1,5 @@
-package io.jsonwebtoken.io.impl.orgjson;
+package io.jsonwebtoken.io;
-import io.jsonwebtoken.io.DeserializationException;
-import io.jsonwebtoken.io.Deserializer;
import io.jsonwebtoken.lang.Assert;
import io.jsonwebtoken.lang.Strings;
import org.json.JSONArray;
@@ -14,6 +12,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+/**
+ * @since 0.10.0
+ */
public class OrgJsonDeserializer implements Deserializer