Fix locator paths and added tests.

This commit is contained in:
Andrea Paternesi 2019-07-16 16:19:13 +02:00
parent 486305f6c3
commit 134f25b536
4 changed files with 42 additions and 2 deletions

View File

@ -34,7 +34,7 @@ public class RuntimeClasspathDeserializerLocator<T> implements InstanceLocator<D
return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer");
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonDeserializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer");
} else if (isAvailable("com.google.gson.GsonBuilder")) {
} else if (isAvailable("io.jsonwebtoken.io.GsonDeSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.GsonDeSerializer");
} else {
throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath.");

View File

@ -34,7 +34,7 @@ public class RuntimeClasspathSerializerLocator implements InstanceLocator<Serial
return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer");
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer");
} else if (isAvailable("com.google.gson.GsonBuilder")) {
} else if (isAvailable("io.jsonwebtoken.io.GsonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.GsonSerializer");
} else {
throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath.");

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import io.jsonwebtoken.io.Deserializer
import io.jsonwebtoken.io.JacksonDeserializer
import io.jsonwebtoken.io.OrgJsonDeserializer
import io.jsonwebtoken.io.GsonDeserializer
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -96,4 +97,23 @@ class RuntimeClasspathDeserializerLocatorTest {
def deserializer = locator.getInstance()
assertTrue deserializer instanceof OrgJsonDeserializer
}
@Test
void testGson() {
def locator = new RuntimeClasspathDeserializerLocator() {
@Override
protected boolean isAvailable(String fqcn) {
if (JacksonDeserializer.class.getName().equals(fqcn)) {
return false; //skip it to allow the Gson impl to be created
}
if (OrgJsonDeserializer.class.getName().equals(fqcn)) {
return false; //skip it to allow the Gson impl to be created
}
return super.isAvailable(fqcn)
}
}
def deserializer = locator.getInstance()
assertTrue deserializer instanceof GsonDeserializer
}
}

View File

@ -3,6 +3,7 @@ package io.jsonwebtoken.impl.io
import io.jsonwebtoken.io.Serializer
import io.jsonwebtoken.io.JacksonSerializer
import io.jsonwebtoken.io.OrgJsonSerializer
import io.jsonwebtoken.io.GsonSerializer
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -95,4 +96,23 @@ class RuntimeClasspathSerializerLocatorTest {
def serializer = locator.getInstance()
assertTrue serializer instanceof OrgJsonSerializer
}
@Test
void testGson() {
def locator = new RuntimeClasspathSerializerLocator() {
@Override
protected boolean isAvailable(String fqcn) {
if (JacksonSerializer.class.getName().equals(fqcn)) {
return false //skip it to allow the Gson impl to be created
}
if (OrgJsonSerializer.class.getName().equals(fqcn)) {
return false //skip it to allow the Gson impl to be created
}
return super.isAvailable(fqcn)
}
}
def serializer = locator.getInstance()
assertTrue serializer instanceof GsonSerializer
}
}