diff --git a/guava/pom.xml b/guava/pom.xml index 9335f6b1..d9e78e49 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -53,10 +53,15 @@ com.google.common.*;version="${version.guava.osgi}", ${version.guava} - + - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api test diff --git a/guava/src/main/java/module-info.java b/guava/src/main/java/module-info.java index 0487306e..20b13047 100644 --- a/guava/src/main/java/module-info.java +++ b/guava/src/main/java/module-info.java @@ -4,7 +4,7 @@ requires com.fasterxml.jackson.annotation; requires tools.jackson.core; - requires tools.jackson.databind; + requires transitive tools.jackson.databind; requires com.google.common; diff --git a/guava/src/test/java/module-info.java b/guava/src/test/java/module-info.java index 3fa4ca62..608801cb 100644 --- a/guava/src/test/java/module-info.java +++ b/guava/src/test/java/module-info.java @@ -12,7 +12,8 @@ requires com.google.common; // Additional test lib/framework dependencies - requires junit; // JUnit 4 + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; // Further, need to open up test packages for JUnit et al diff --git a/guava/src/test/java/tools/jackson/datatype/guava/CacheDeserializationTest.java b/guava/src/test/java/tools/jackson/datatype/guava/CacheDeserializationTest.java index d32c1b95..0872394c 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/CacheDeserializationTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/CacheDeserializationTest.java @@ -3,6 +3,8 @@ import java.util.Map; import java.util.Objects; +import org.junit.jupiter.api.Test; + import com.google.common.base.Optional; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -16,6 +18,8 @@ import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.MismatchedInputException; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying deserialization of Guava's {@link Cache} type. * @@ -68,6 +72,7 @@ static class CacheWrapper { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testGuavaCacheApi() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); // Cache does not allow null key @@ -83,6 +88,7 @@ public void testGuavaCacheApi() throws Exception { } catch (NullPointerException e) {} } + @Test public void testCacheDeserializationSimple() throws Exception { // Create a delegate cache using CacheBuilder Cache delegateCache = CacheBuilder.newBuilder().build(); @@ -95,6 +101,7 @@ public void testCacheDeserializationSimple() throws Exception { assertEquals("foo", s.getIfPresent("a")); } + @Test public void testCacheDeserRoundTrip() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put("key1", 1); @@ -111,6 +118,7 @@ public void testCacheDeserRoundTrip() throws Exception { } // [datatype-collections#96] + @Test public void testCacheSerialization() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put(1L, 1); @@ -134,6 +142,7 @@ private void _verifySizeTwoAndContains(Map map) { assertEquals(2, map.get(2L).intValue()); } + @Test public void testEnumKey() throws Exception { final TypeReference> type = new TypeReference>() {}; final Cache cache = CacheBuilder.newBuilder().build(); @@ -151,11 +160,13 @@ public void testEnumKey() throws Exception { deserializedCache.asMap().entrySet()); } + @Test public void testEmptyCacheExclusion() throws Exception { String json = MAPPER.writeValueAsString(new CacheWrapper()); assertEquals("{}", json); } + @Test public void testWithGuavaOptional() throws Exception { // set up Cache> cache = CacheBuilder.newBuilder().build(); @@ -175,6 +186,7 @@ public void testWithGuavaOptional() throws Exception { } // [datatypes-collections#140]: handle null values + @Test public void testCacheWithNulls() throws Exception { Cache cache; try { diff --git a/guava/src/test/java/tools/jackson/datatype/guava/CacheSerializationTest.java b/guava/src/test/java/tools/jackson/datatype/guava/CacheSerializationTest.java index b27d78df..c21da610 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/CacheSerializationTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/CacheSerializationTest.java @@ -10,10 +10,13 @@ import com.google.common.base.Objects; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying serialization of Guava's {@link Cache} type. */ @@ -191,6 +194,7 @@ public String toString() { .enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS) .build(); + @Test public void testGuavaCacheApi() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); // Cache does not allow null key @@ -206,6 +210,7 @@ public void testGuavaCacheApi() throws Exception { } catch (NullPointerException e) {} } + @Test public void testCacheSerialization() throws Exception { // Create a Guava Cache Cache cache = CacheBuilder.newBuilder().build(); @@ -217,6 +222,7 @@ public void testCacheSerialization() throws Exception { ORDERED_MAPPER.writeValueAsString(cache)); } + @Test public void testCacheSerializationIgnoreProperties() throws Exception { CacheContainerWithIgnores container = new CacheContainerWithIgnores(); @@ -225,6 +231,7 @@ public void testCacheSerializationIgnoreProperties() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithBean() throws Exception { CacheContainerWithBean container = new CacheContainerWithBean(); @@ -233,6 +240,7 @@ public void testCacheSerializationWithBean() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithList() throws Exception { CacheContainerWithList container = new CacheContainerWithList(); @@ -241,6 +249,7 @@ public void testCacheSerializationWithList() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithEmptyCache() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); @@ -249,6 +258,7 @@ public void testCacheSerializationWithEmptyCache() throws Exception { ORDERED_MAPPER.writeValueAsString(cache)); } + @Test public void testCacheSerializationBeanKey() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put(new BeanKey(1), "value1"); @@ -258,6 +268,7 @@ public void testCacheSerializationBeanKey() throws Exception { ORDERED_MAPPER.writeValueAsString(cache)); } + @Test public void testCacheSerializationBeanKeyEquals() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put(new BeanKeyEquals(1), "value1"); @@ -270,12 +281,14 @@ public void testCacheSerializationBeanKeyEquals() throws Exception { } + @Test public void testEmptyCacheExclusion() throws Exception { String json = ORDERED_MAPPER.writeValueAsString(new CacheWrapper()); assertEquals("{}", json); } + @Test public void testCacheSerializationWithTypeReference() throws Exception { final Cache cache = CacheBuilder.newBuilder().build(); cache.put(MyEnum.YAY, 5); @@ -289,6 +302,7 @@ public void testCacheSerializationWithTypeReference() throws Exception { assertEquals(expected, mapperSer); } + @Test public void testOrderByKeyViaProperty() throws Exception { CacheOrderingBean input = new CacheOrderingBean("c", "b", "a"); @@ -297,6 +311,7 @@ public void testOrderByKeyViaProperty() throws Exception { assertEquals(a2q("{'cache':{'a':3,'b':2,'c':1}}"), json); } + @Test public void testPolymorphicCacheSerialization() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put("c", new Cat()); @@ -311,6 +326,7 @@ public void testPolymorphicCacheSerialization() throws Exception { "'d':{'_type':'t_dog','name':'Woof'}}}"), json); } + @Test public void testNestedCacheSerialization() throws Exception { Cache> nestedCache = CacheBuilder.newBuilder().build(); nestedCache.put("a", _buildCacheWithKeys("a_x", "a_y")); @@ -333,6 +349,7 @@ private Cache _buildCacheWithKeys(String... keys) { } // [datatypes-collections#104] + @Test public void testPolymorphicCacheEmpty() throws Exception { final Cache cache = CacheBuilder.newBuilder().build(); cache.put("aKey", 1); @@ -340,6 +357,7 @@ public void testPolymorphicCacheEmpty() throws Exception { a2q("{'aProperty':{'@type':'LocalCache$LocalManualCache','aKey':1}}")); } + @Test public void testPolymorphicCacheNonEmpty() throws Exception { _testPolymorphicCache(CacheBuilder.newBuilder().build(), a2q("{'aProperty':{'@type':'LocalCache$LocalManualCache'}}")); @@ -354,6 +372,7 @@ private void _testPolymorphicCache(Cache cache, String expected) assertEquals(expected, json); } + @Test public void testCacheSerializeOrderedByKey() throws Exception { final Cache cache = _buildCacheWithKeys("c_key", "d_key", "a_key", "e_key", "b_key"); @@ -365,6 +384,7 @@ public void testCacheSerializeOrderedByKey() throws Exception { new TypeReference>() {}).writeValueAsString(cache)); } + @Test public void testPolymorphicCacheWrapperSerialization() throws Exception { final Cache cache = _buildCacheWithKeys("c_key", "a_key", "e_key", "b_key", "d_key"); PolymorphicWrapperBean outside = new PolymorphicWrapperBean(); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/EmptyCollectionsTest.java b/guava/src/test/java/tools/jackson/datatype/guava/EmptyCollectionsTest.java index 1ca6e3b4..11163e8a 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/EmptyCollectionsTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/EmptyCollectionsTest.java @@ -1,11 +1,15 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.Nulls; import tools.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import static org.junit.jupiter.api.Assertions.*; + public class EmptyCollectionsTest extends ModuleTestBase { // [datatypes-collections#67] @@ -24,6 +28,7 @@ public static class ImmutableMapContainer67 { .build(); // [datatypes-collections#67] + @Test public void testEmptyForLists() throws Exception { ImmutableListContainer67 result; @@ -47,6 +52,7 @@ public void testEmptyForLists() throws Exception assertEquals(0, result.lists.size()); } + @Test public void testEmptyForMaps() throws Exception { ImmutableMapContainer67 result; diff --git a/guava/src/test/java/tools/jackson/datatype/guava/FluentIterableTest.java b/guava/src/test/java/tools/jackson/datatype/guava/FluentIterableTest.java index 2cbf9276..1221bcc6 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/FluentIterableTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/FluentIterableTest.java @@ -2,10 +2,14 @@ import java.util.Arrays; +import org.junit.jupiter.api.Test; + import com.google.common.collect.FluentIterable; import tools.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Unit tests to verify serialization of {@link FluentIterable}s. */ @@ -27,6 +31,7 @@ static FluentIterable createFluentIterable() { * or Guava's implementation of FluentIterable changes. * @throws Exception */ + @Test public void testSerializationWithoutModule() throws Exception { ObjectMapper mapper = new ObjectMapper(); FluentHolder holder = new FluentHolder(); @@ -34,15 +39,16 @@ public void testSerializationWithoutModule() throws Exception { assertEquals("{\"value\":{\"empty\":false}}", json); } + @Test public void testSerialization() throws Exception { String json = MAPPER.writeValueAsString(createFluentIterable()); assertEquals("[1,2,3]", json); } + @Test public void testWrappedSerialization() throws Exception { FluentHolder holder = new FluentHolder(); String json = MAPPER.writeValueAsString(holder); assertEquals("{\"value\":[1,2,3]}", json); } - } diff --git a/guava/src/test/java/tools/jackson/datatype/guava/HashCodeTest.java b/guava/src/test/java/tools/jackson/datatype/guava/HashCodeTest.java index a4d2cfbd..728e61de 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/HashCodeTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/HashCodeTest.java @@ -1,14 +1,19 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + +import com.google.common.hash.HashCode; + import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.MismatchedInputException; -import com.google.common.hash.HashCode; +import static org.junit.jupiter.api.Assertions.*; public class HashCodeTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testSerialization() throws Exception { HashCode input = HashCode.fromString("cafebabe12345678"); @@ -16,6 +21,7 @@ public void testSerialization() throws Exception assertEquals("\"cafebabe12345678\"", json); } + @Test public void testDeserialization() throws Exception { // success: diff --git a/guava/src/test/java/tools/jackson/datatype/guava/HostAndPortTest.java b/guava/src/test/java/tools/jackson/datatype/guava/HostAndPortTest.java index e331ea1c..9e375e14 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/HostAndPortTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/HostAndPortTest.java @@ -1,14 +1,19 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + +import com.google.common.net.HostAndPort; + import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.MismatchedInputException; -import com.google.common.net.HostAndPort; +import static org.junit.jupiter.api.Assertions.*; public class HostAndPortTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testSerialization() throws Exception { HostAndPort input = HostAndPort.fromParts("localhost", 80); @@ -16,6 +21,7 @@ public void testSerialization() throws Exception assertEquals("\"localhost:80\"", json); } + @Test public void testDeserializationOk() throws Exception { // Actually, let's support both old style and new style @@ -44,6 +50,7 @@ public void testDeserializationOk() throws Exception assertEquals(HostAndPort.fromHost(""), result); } + @Test public void testDeserializationFail() throws Exception { HostAndPort result = null; diff --git a/guava/src/test/java/tools/jackson/datatype/guava/ImmutableContainersTest.java b/guava/src/test/java/tools/jackson/datatype/guava/ImmutableContainersTest.java index 380956c7..1e26c621 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/ImmutableContainersTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/ImmutableContainersTest.java @@ -2,6 +2,8 @@ import java.util.Iterator; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import tools.jackson.core.type.TypeReference; @@ -14,6 +16,8 @@ import com.google.common.collect.*; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying that various immutable types * (like {@link ImmutableList}, {@link ImmutableMap} and {@link ImmutableSet}) @@ -53,6 +57,7 @@ public PolymorphicHolder(Object v) { * Immutable types can actually be serialized as regular collections, without * problems. */ + @Test public void testWithoutSerializers() throws Exception { ImmutableList list = ImmutableList.builder() @@ -79,6 +84,7 @@ public void testWithoutSerializers() throws Exception /** * Deserialization will fail, however. */ + @Test public void testWithoutDeserializersFail() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -126,6 +132,7 @@ private void _verifyImmutableException(InvalidDefinitionException e, Class ty /********************************************************************** */ + @Test public void testImmutableList() throws Exception { ImmutableList list = MAPPER.readValue("[1,2,3]", new TypeReference>() { }); @@ -135,6 +142,7 @@ public void testImmutableList() throws Exception assertEquals(Integer.valueOf(3), list.get(2)); } + @Test public void testImmutableSet() throws Exception { ImmutableSet set = MAPPER.readValue("[3,7,8]", @@ -150,6 +158,7 @@ public void testImmutableSet() throws Exception assertEquals(0, set.size()); } + @Test public void testImmutableSetFromSingle() throws Exception { ObjectMapper mapper = builderWithModule() @@ -161,6 +170,7 @@ public void testImmutableSetFromSingle() throws Exception assertTrue(set.contains("abc")); } + @Test public void testImmutableSortedSet() throws Exception { ImmutableSortedSet set = MAPPER.readValue("[5,1,2]", new TypeReference>() { }); @@ -170,7 +180,8 @@ public void testImmutableSortedSet() throws Exception assertEquals(Integer.valueOf(2), it.next()); assertEquals(Integer.valueOf(5), it.next()); } - + + @Test public void testImmutableMap() throws Exception { final JavaType type = MAPPER.getTypeFactory().constructType(new TypeReference>() { }); @@ -188,6 +199,7 @@ public void testImmutableMap() throws Exception assertEquals(1, map.size()); } + @Test public void testImmutableSortedMap() throws Exception { ImmutableSortedMap map = MAPPER.readValue("{\"12\":true,\"4\":false}", new TypeReference>() { }); @@ -195,7 +207,8 @@ public void testImmutableSortedMap() throws Exception assertEquals(Boolean.TRUE, map.get(Integer.valueOf(12))); assertEquals(Boolean.FALSE, map.get(Integer.valueOf(4))); } - + + @Test public void testImmutableBiMap() throws Exception { ImmutableBiMap map = MAPPER.readValue("{\"12\":true,\"4\":false}", new TypeReference>() { }); @@ -212,6 +225,7 @@ public void testImmutableBiMap() throws Exception /********************************************************************** */ + @Test public void testTypedImmutableset() throws Exception { ImmutableSet set; @@ -244,6 +258,7 @@ public void testTypedImmutableset() throws Exception assertEquals(0, ((ImmutableSet) result.value).size()); } + @Test public void testTypedImmutableMap() throws Exception { ImmutableMap map; diff --git a/guava/src/test/java/tools/jackson/datatype/guava/IterablesTest.java b/guava/src/test/java/tools/jackson/datatype/guava/IterablesTest.java index 0c0af38b..256a960d 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/IterablesTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/IterablesTest.java @@ -1,11 +1,15 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonInclude; import tools.jackson.databind.ObjectMapper; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; +import static org.junit.jupiter.api.Assertions.*; + public class IterablesTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); @@ -23,6 +27,7 @@ static class IterableWrapper { /********************************************************** */ + @Test public void testIterablesSerialization() throws Exception { String json = MAPPER.writeValueAsString(Iterables.limit(Iterables.cycle(1,2,3), 3)); @@ -31,6 +36,7 @@ public void testIterablesSerialization() throws Exception } // for [#60] + @Test public void testIterablesWithTransform() throws Exception { Iterable input = Iterables.transform(ImmutableList.of("mr", "bo", "jangles"), diff --git a/guava/src/test/java/tools/jackson/datatype/guava/JavaSerializableTest.java b/guava/src/test/java/tools/jackson/datatype/guava/JDKSerializableTest.java similarity index 89% rename from guava/src/test/java/tools/jackson/datatype/guava/JavaSerializableTest.java rename to guava/src/test/java/tools/jackson/datatype/guava/JDKSerializableTest.java index 1486af1c..d95d5f36 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/JavaSerializableTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/JDKSerializableTest.java @@ -1,17 +1,20 @@ package tools.jackson.datatype.guava; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; + +import org.junit.jupiter.api.Test; -import tools.jackson.core.type.TypeReference; -import tools.jackson.databind.ObjectMapper; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; -public class JavaSerializableTest extends ModuleTestBase { +import tools.jackson.core.type.TypeReference; +import tools.jackson.databind.ObjectMapper; + +import static org.junit.jupiter.api.Assertions.*; +public class JDKSerializableTest extends ModuleTestBase +{ + @Test public void testSerializable() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -23,6 +26,7 @@ public void testSerializable() throws Exception { assertTrue(set.contains("abc")); } + @Test public void testSerializableConfigureAbsentsAsNull() throws Exception { ObjectMapper mapper = mapperWithModule(true); @@ -52,7 +56,7 @@ private ObjectMapper serializeAndDeserialize(ObjectMapper mapper) throws Excepti Object deserializedObject = inputStream.readObject(); - //validate the object + // Actually `JsonMapper` but basic `ObjectMapper` works here return (ObjectMapper) deserializedObject; } } diff --git a/guava/src/test/java/tools/jackson/datatype/guava/JsonDeserContentConverter92Test.java b/guava/src/test/java/tools/jackson/datatype/guava/JsonDeserContentConverter92Test.java index e782500e..2c2875c5 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/JsonDeserContentConverter92Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/JsonDeserContentConverter92Test.java @@ -4,12 +4,15 @@ import java.util.Arrays; import java.util.List; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.*; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.annotation.JsonDeserialize; import tools.jackson.databind.annotation.JsonSerialize; import tools.jackson.databind.util.StdConverter; -import com.google.common.collect.*; +import static org.junit.jupiter.api.Assertions.*; // [datatype-guava#92] : JsonDeserialize contentConverter does not work for non-builtin collections public class JsonDeserContentConverter92Test extends ModuleTestBase { @@ -88,6 +91,7 @@ static class GuavaImmutableBiMapHolder { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testJsonSerialize() throws Exception { String jsonStr = a2q("{'list':[2,4]}"); @@ -95,6 +99,7 @@ public void testJsonSerialize() throws Exception { assertEquals(jsonStr, _write(new GuavaListWrapper(ImmutableList.of(1, 2)))); } + @Test public void testJsonDeserialize() throws Exception { String withIntsArr = a2q("{'ints': [1,2,3] }"); String withIntsMap = a2q("{'ints': {'one':1, 'two':2, 'three':3}}"); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/ModuleTestBase.java b/guava/src/test/java/tools/jackson/datatype/guava/ModuleTestBase.java index 338784d1..d0203d1d 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/ModuleTestBase.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/ModuleTestBase.java @@ -2,14 +2,14 @@ import java.util.Arrays; -import tools.jackson.databind.DatabindContext; -import tools.jackson.databind.JavaType; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.*; import tools.jackson.databind.cfg.MapperBuilder; import tools.jackson.databind.json.JsonMapper; import tools.jackson.databind.jsontype.PolymorphicTypeValidator; -public abstract class ModuleTestBase extends junit.framework.TestCase +import static org.junit.jupiter.api.Assertions.fail; + +public abstract class ModuleTestBase { public static class NoCheckSubTypeValidator extends PolymorphicTypeValidator.Base diff --git a/guava/src/test/java/tools/jackson/datatype/guava/MultiMap104Test.java b/guava/src/test/java/tools/jackson/datatype/guava/MultiMap104Test.java index 199ed94f..7f8ff8d7 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/MultiMap104Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/MultiMap104Test.java @@ -1,10 +1,14 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ArrayListMultimap; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import tools.jackson.databind.*; -import com.google.common.collect.ArrayListMultimap; +import static org.junit.jupiter.api.Assertions.*; public class MultiMap104Test extends ModuleTestBase { @@ -20,12 +24,14 @@ static class Outside104 { // [datatypes-collections#104] + @Test public void testPolymorphicArrayMapEmpty() throws Exception { final ArrayListMultimap multimap = ArrayListMultimap.create(); multimap.put("aKey", 1); _testPolymorphicArrayMap(multimap); } + @Test public void testPolymorphicArrayMapNonEmpty() throws Exception { _testPolymorphicArrayMap(ArrayListMultimap.create()); } diff --git a/guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java b/guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderEntriesByKeys7Test.java similarity index 96% rename from guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java rename to guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderEntriesByKeys7Test.java index bdb21cd4..8715091f 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/MultiMapOrderEntriesByKeys7Test.java @@ -3,16 +3,17 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.annotation.JsonTypeInfo; - -import tools.jackson.databind.*; +import org.junit.jupiter.api.Test; import com.google.common.collect.*; -import static org.junit.Assert.assertNotEquals; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import tools.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.*; // [jackson-datatype-collections#7]: [Guava] Add support for WRITE_SORTED_MAP_ENTRIES -public class MultiMapOrderMpEntriesByKeys7Test extends ModuleTestBase +public class MultiMapOrderEntriesByKeys7Test extends ModuleTestBase { /* /********************************************************** @@ -51,6 +52,7 @@ public String toString() { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testMultimapSerializeOrderedByKey() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); @@ -66,6 +68,7 @@ public void testMultimapSerializeOrderedByKey() throws Exception { assertEquals(a2q("{'a_key':[1],'b_key':[1],'c_key':[1],'d_key':[1],'e_key':[1]}"), jsonStr); } + @Test public void testMultimapSerializeUnorderedByKey() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); @@ -82,6 +85,7 @@ public void testMultimapSerializeUnorderedByKey() throws Exception { } + @Test public void testMultimapSerializeWithNullKeyFailure() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); @@ -99,6 +103,7 @@ public void testMultimapSerializeWithNullKeyFailure() throws Exception { } } + @Test public void testMultimapSerializeUncomparablePojo() throws Exception { final Multimap multimap = ArrayListMultimap.create(); multimap.put(new UncomparableBean("c_key"), 1); @@ -114,6 +119,7 @@ public void testMultimapSerializeUncomparablePojo() throws Exception { assertNotNull(a2q("{'a_key':[1],'b_key':[1],'c_key':[1],'d_key':[1],'e_key':[1]}"), jsonStr); } + @Test public void testSerializeAllTypesOfMultimapOrdered() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); @@ -140,6 +146,7 @@ public void testSerializeAllTypesOfMultimapOrdered() throws Exception { } } + @Test public void testPolymorphicArrayMap() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/MultimapsTest.java b/guava/src/test/java/tools/jackson/datatype/guava/MultimapsTest.java index 8a463296..2d8d380b 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/MultimapsTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/MultimapsTest.java @@ -1,25 +1,25 @@ package tools.jackson.datatype.guava; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; +import java.util.*; + +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; +import com.google.common.collect.*; import com.fasterxml.jackson.annotation.*; import tools.jackson.core.type.TypeReference; -import tools.jackson.databind.DeserializationFeature; -import tools.jackson.databind.ObjectMapper; -import tools.jackson.databind.ObjectReader; +import tools.jackson.databind.*; import tools.jackson.datatype.guava.pojo.AddOp; import tools.jackson.datatype.guava.pojo.MathOp; import tools.jackson.datatype.guava.pojo.MulOp; -import com.google.common.base.Optional; -import com.google.common.collect.*; - import static com.google.common.collect.TreeMultimap.create; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests to verify handling of various {@link Multimap}s. * @@ -103,7 +103,8 @@ public boolean equals(Object obj) { private final ObjectMapper MAPPER = mapperWithModule(); - public void testMultimap() + @Test + public void testMultimap() throws Exception { _testMultimap(TreeMultimap.create(), true, "{\"false\":[false],\"maybe\":[false,true],\"true\":[true]}"); @@ -143,7 +144,8 @@ private void _testMultimap(Multimap map0, boolean fullyOrdered, String EXPE } } - public void testMultimapIssue3() + @Test + public void testMultimapIssue3() throws Exception { Multimap m1 = TreeMultimap.create(); m1.put("foo", "bar"); @@ -173,7 +175,8 @@ public void testMultimapIssue3() assertEquals(2, javaMap.size()); } - public void testEnumKey() + @Test + public void testEnumKey() throws Exception { final TypeReference> type = new TypeReference>() {}; final Multimap map = TreeMultimap.create(); @@ -188,12 +191,14 @@ public void testEnumKey() } // [Issue#41] - public void testEmptyMapExclusion() + @Test + public void testEmptyMapExclusion() throws Exception { String json = MAPPER.writeValueAsString(new MultiMapWrapper()); assertEquals("{}", json); } + @Test public void testNullHandling() throws Exception { Multimap input = ArrayListMultimap.create(); @@ -203,7 +208,8 @@ public void testNullHandling() throws Exception } // [datatypes-collections#27]: - public void testWithReferenceType() + @Test + public void testWithReferenceType() throws Exception { String json = "{\"a\" : [5.0, null, 6.0]}"; ListMultimap> result = MAPPER.readValue( @@ -233,21 +239,24 @@ public void testForwardingSortedSetMultimap() { } */ - public void testImmutableSetMultimap() { + @Test + public void testImmutableSetMultimap() throws Exception { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { }); assertTrue(map instanceof ImmutableSetMultimap); } - public void testHashMultimap() { + @Test + public void testHashMultimap() throws Exception { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { }); assertTrue(map instanceof HashMultimap); } - public void testLinkedHashMultimap() { + @Test + public void testLinkedHashMultimap() throws Exception { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { }); @@ -277,21 +286,24 @@ private SetMultimap _verifyMultiMapRead(TypeReference type) /********************************************************************** */ - public void testArrayListMultimap() { + @Test + public void testArrayListMultimap() throws Exception { ListMultimap map = listBasedHelper(new TypeReference>() { }); assertTrue(map instanceof ArrayListMultimap); } - public void testLinkedListMultimap() { + @Test + public void testLinkedListMultimap() throws Exception { ListMultimap map = listBasedHelper(new TypeReference>() { }); assertTrue(map instanceof LinkedListMultimap); } - public void testMultimapWithIgnores() { + @Test + public void testMultimapWithIgnores() throws Exception { assertEquals("{\"map\":{\"a\":[\"foo\"]}}", MAPPER.writeValueAsString(new MultiMapWithIgnores())); } @@ -309,7 +321,8 @@ private ListMultimap listBasedHelper(TypeReference type) return map; } - public void testIssue67() + @Test + public void testIssue67() throws Exception { ImmutableSetMultimap map = MAPPER.readValue( "{\"d\":[1,2],\"c\":[3,4],\"b\":[5,6],\"a\":[7,8]}", @@ -327,17 +340,17 @@ public void testIssue67() assertEquals(Maps.immutableEntry("a", 8), iterator.next()); } - public void testDefaultSetMultiMap() - { + @Test + public void testDefaultSetMultiMap() throws Exception { @SuppressWarnings("unchecked") SetMultimap map = (SetMultimap) MAPPER .readValue( "{\"first\":[\"abc\",\"abc\",\"foo\"]," + "\"second\":[\"bar\"]}", SetMultimap.class); assertTrue(map instanceof LinkedHashMultimap); } - - public void testPolymorphicValue() - { + + @Test + public void testPolymorphicValue() throws Exception { ImmutableMultimapWrapper input = new ImmutableMultimapWrapper(ImmutableMultimap.of("add", new AddOp(3, 2), "mul", new MulOp(4, 6))); String json = MAPPER.writeValueAsString(input); @@ -345,8 +358,9 @@ public void testPolymorphicValue() ImmutableMultimapWrapper output = MAPPER.readValue(json, ImmutableMultimapWrapper.class); assertEquals(input, output); } - - public void testFromSingleValue() + + @Test + public void testFromSingleValue() throws Exception { ObjectMapper mapper = builderWithModule() .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) @@ -356,8 +370,9 @@ public void testFromSingleValue() assertEquals(1, sampleTest.map.get("test").size()); } - - public void testFromMultiValueWithSingleValueOptionEnabled() + + @Test + public void testFromMultiValueWithSingleValueOptionEnabled() throws Exception { ObjectReader r = MAPPER.reader() .with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @@ -370,8 +385,9 @@ public void testFromMultiValueWithSingleValueOptionEnabled() // Make sure that our Value is still a String not [String] assertEquals(sampleTest.map.entries().iterator().next().getValue(), "val"); } - - public void testFromMultiValueWithNoSingleValueOptionEnabled() + + @Test + public void testFromMultiValueWithNoSingleValueOptionEnabled() throws Exception { SampleMultiMapTest sampleTest = MAPPER.readValue("{\"map\":{\"test\":[\"val\"],\"test1\":[\"val1\",\"val2\"]}}", new TypeReference() { }); @@ -405,6 +421,7 @@ ArrayListMultimap mapValue() { } // [datatype-collections#96] + @Test public void testMultimapIssue96() throws Exception { // First the original, properties case: diff --git a/guava/src/test/java/tools/jackson/datatype/guava/MultisetsTest.java b/guava/src/test/java/tools/jackson/datatype/guava/MultisetsTest.java index 648923ed..2700226a 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/MultisetsTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/MultisetsTest.java @@ -1,12 +1,16 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.*; + import tools.jackson.core.type.TypeReference; import tools.jackson.databind.*; import tools.jackson.databind.exc.InvalidDefinitionException; import tools.jackson.databind.exc.MismatchedInputException; -import com.google.common.collect.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests to verify handling of various {@link Multiset}s. @@ -23,6 +27,7 @@ public class MultisetsTest extends ModuleTestBase * Multi-sets can actually be serialized as regular collections, without * problems. */ + @Test public void testWithoutSerializers() throws Exception { @@ -37,6 +42,7 @@ public void testWithoutSerializers() throws Exception } // 11-Jul-2017, tatu: Not sure if this test makes sense actually... + @Test public void testWithoutDeserializers() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -60,32 +66,39 @@ public void testWithoutDeserializers() throws Exception */ private final ObjectMapper MAPPER = mapperWithModule(); - + + @Test public void testDefaultMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } - + + @Test public void testDefaultSortedMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } + @Test public void testLinkedHashMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } - + + @Test public void testHashMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } - + + @Test public void testTreeMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } - + + @Test public void testImmutableMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } + @Test public void testImmutableSortedMultiset() throws Exception { _testMultiset(new TypeReference>() { }); } @@ -111,6 +124,7 @@ private > void _testMultiset(TypeReference typeRef } } + @Test public void testFromSingle() throws Exception { ObjectMapper mapper = builderWithModule() diff --git a/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer102Test.java b/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer102Test.java index 2417eca7..61c4f5ed 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer102Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer102Test.java @@ -1,5 +1,7 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.google.common.collect.BoundType; import com.google.common.collect.Range; @@ -9,6 +11,8 @@ import tools.jackson.databind.exc.InvalidFormatException; import tools.jackson.databind.json.JsonMapper; +import static org.junit.jupiter.api.Assertions.*; + public class RangeDeserializer102Test extends ModuleTestBase { private final ObjectMapper MAPPER_DEFAULT = mapperWithModule(); @@ -17,6 +21,7 @@ public class RangeDeserializer102Test extends ModuleTestBase .build(); // [datatypes-collections#56]: support naming strategy + @Test public void testSnakeCaseNamingStrategy() throws Exception { String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}"; @@ -38,11 +43,13 @@ public void testSnakeCaseNamingStrategy() throws Exception } // [datatypes-collections#102]: Accept lowerCase enums for `Range` `BoundType` serialization + @Test public void testDeserializeDefaultSuccess() throws Exception { _testDeserializeOk(MAPPER_DEFAULT, "CLOSED", "OPEN"); } + @Test public void testDeserializeAcceptCaseInsensitiveBoundTypeSuccess() throws Exception { _testDeserializeOk(MAPPER_CASE_INSENSITIVE, "CLOSED", "OPEN"); @@ -64,6 +71,7 @@ private void _testDeserializeOk(ObjectMapper mapper, assertEquals(BoundType.OPEN, range.upperBoundType()); } + @Test public void testDeserializeBoundTypeFailWithFirstInvalidValue() throws Exception { String json = a2q("{'lowerEndpoint': 1, 'lowerBoundType': 'closed', 'upperEndpoint': 2, 'upperBoundType': 'oPeN'}"); try { @@ -75,6 +83,7 @@ public void testDeserializeBoundTypeFailWithFirstInvalidValue() throws Exception } } + @Test public void testDeserializeBoundTypeFailWithFirstInvalidValueFlip() throws Exception { String json = a2q("{'upperEndpoint': 2, 'upperBoundType': 'oPeN', 'lowerEndpoint': 1, 'lowerBoundType': 'closed'}"); try { diff --git a/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer188Test.java b/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer188Test.java index 11ad81df..7b1eabfd 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer188Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/RangeDeserializer188Test.java @@ -3,16 +3,20 @@ import java.time.Duration; import java.time.LocalDate; -import com.fasterxml.jackson.annotation.JsonFormat; +import org.junit.jupiter.api.Test; import com.google.common.collect.Range; +import com.fasterxml.jackson.annotation.JsonFormat; + import tools.jackson.core.type.TypeReference; import tools.jackson.databind.JavaType; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.InvalidFormatException; import tools.jackson.datatype.guava.deser.util.RangeFactory; +import static org.junit.jupiter.api.Assertions.*; + // Test for [dataformats-collections#118] public class RangeDeserializer188Test extends ModuleTestBase { @@ -52,6 +56,7 @@ public Range toRange() { private static final Range rightBoundedRange = RangeFactory.atLeast(10); // [dataformats-collections#118] + @Test public void testRangeSerializationToString() throws Exception { testRangeSerialization(openRange, "(1..10)"); @@ -68,6 +73,7 @@ public void testRangeSerializationToString() throws Exception } // [dataformats-collections#135] + @Test public void testIntRangeDeserializationFromBracketNotation() throws Exception { testIntRangeDeserialization("{\"r\":\"(1..10)\"}", openRange); @@ -80,12 +86,14 @@ public void testIntRangeDeserializationFromBracketNotation() throws Exception testIntRangeDeserialization("{\"r\":\"[10..+∞)\"}", rightBoundedRange); } + @Test public void testStringRangeDeserializationFromBracketNotation() throws Exception { _testStringifiedRangeDeserialization("{\"r\":\"(abc..def]\"}", openClosedStringRange, String.class); } + @Test public void testCharacterRangeDeserializationFromBracketNotation() throws Exception { _testStringifiedRangeDeserialization("{\"r\":\"[a..z)\"}", @@ -93,6 +101,7 @@ public void testCharacterRangeDeserializationFromBracketNotation() throws Except } // Cannot implement here since `Duration` KeyDeserializer provided by Java 8 date/time module + @Test public void testDurationRangeDeserializationFromBracketNotation() throws Exception { /* @@ -102,6 +111,7 @@ public void testDurationRangeDeserializationFromBracketNotation() throws Excepti } // Cannot implement here since `LocalDate` KeyDeserializer provided by Java 8 date/time module + @Test public void testLocalDateRangeDeserializationFromBracketNotation() throws Exception { /* @@ -110,6 +120,7 @@ public void testLocalDateRangeDeserializationFromBracketNotation() throws Except */ } + @Test public void testInvalidBracketNotationRangeDeserialization() throws Exception { // Fails due to open/close markers testInvalidStringifiedDeserialization("[1..2", RangeError.INVALID_BRACKET); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/RangeSetTest.java b/guava/src/test/java/tools/jackson/datatype/guava/RangeSetTest.java index 2fa38368..9d0a4eac 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/RangeSetTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/RangeSetTest.java @@ -1,5 +1,12 @@ package tools.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ImmutableRangeSet; +import com.google.common.collect.Range; +import com.google.common.collect.RangeSet; +import com.google.common.collect.TreeRangeSet; + import tools.jackson.core.type.TypeReference; import tools.jackson.databind.JavaType; import tools.jackson.databind.ObjectMapper; @@ -7,15 +14,13 @@ import tools.jackson.databind.exc.MismatchedInputException; import tools.jackson.databind.type.TypeFactory; -import com.google.common.collect.ImmutableRangeSet; -import com.google.common.collect.Range; -import com.google.common.collect.RangeSet; -import com.google.common.collect.TreeRangeSet; +import static org.junit.jupiter.api.Assertions.*; public class RangeSetTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testSerializeDeserialize() throws Exception { final RangeSet rangeSet = TreeRangeSet.create(); @@ -32,6 +37,7 @@ public void testSerializeDeserialize() throws Exception { assertEquals(rangeSet, deserialized); } + @Test public void testSerializeDeserializeImmutableRangeSet() throws Exception { final ImmutableRangeSet rangeSet = ImmutableRangeSet.builder() .add(Range.closedOpen(1, 2)) @@ -48,6 +54,7 @@ public void testSerializeDeserializeImmutableRangeSet() throws Exception { } // [datatypes-collections#142]: nulls in RangeSet JSON + @Test public void testDeserializeFromNull() throws Exception { final String json = a2q("[ {'lowerEndpoint':1,'lowerBoundType':'CLOSED'}, null ]"); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/RangeTest.java b/guava/src/test/java/tools/jackson/datatype/guava/RangeTest.java index 795d2b83..014ce1e6 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/RangeTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/RangeTest.java @@ -1,9 +1,10 @@ package tools.jackson.datatype.guava; -import java.io.IOException; +import org.junit.jupiter.api.Test; import com.google.common.collect.BoundType; import com.google.common.collect.Range; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import tools.jackson.core.type.TypeReference; @@ -16,6 +17,8 @@ import tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator; import tools.jackson.datatype.guava.deser.util.RangeFactory; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests to verify serialization of Guava {@link Range}s. */ @@ -44,6 +47,7 @@ public Wrapped() { } * or Guava's implementation of Range changes. * @throws Exception */ + @Test public void testSerializationWithoutModule() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -52,6 +56,7 @@ public void testSerializationWithoutModule() throws Exception assertEquals("{\"empty\":false}", json); } + @Test public void testSerialization() throws Exception { testSerialization(MAPPER, RangeFactory.open(1, 10)); @@ -66,6 +71,7 @@ public void testSerialization() throws Exception testSerialization(MAPPER, RangeFactory.singleton(1)); } + @Test public void testSerializationWithPropertyNamingStrategy() throws Exception { ObjectMapper mappper = builderWithModule().propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).build(); @@ -81,6 +87,7 @@ public void testSerializationWithPropertyNamingStrategy() throws Exception testSerialization(mappper, RangeFactory.singleton(1)); } + @Test public void testWrappedSerialization() throws Exception { testSerializationWrapped(MAPPER, RangeFactory.open(1, 10)); @@ -93,7 +100,8 @@ public void testWrappedSerialization() throws Exception testSerializationWrapped(MAPPER, RangeFactory.lessThan(10)); testSerializationWrapped(MAPPER, RangeFactory.singleton(1)); } - + + @Test public void testDeserialization() throws Exception { String json = MAPPER.writeValueAsString(RangeFactory.open(1, 10)); @@ -104,20 +112,21 @@ public void testDeserialization() throws Exception assertEquals(Integer.valueOf(10), r.upperEndpoint()); } - private void testSerialization(ObjectMapper objectMapper, Range range) throws IOException + private void testSerialization(ObjectMapper objectMapper, Range range) throws Exception { String json = objectMapper.writeValueAsString(range); Range rangeClone = objectMapper.readValue(json, Range.class); assertEquals(rangeClone, range); } - private void testSerializationWrapped(ObjectMapper objectMapper, Range range) throws IOException + private void testSerializationWrapped(ObjectMapper objectMapper, Range range) throws Exception { String json = objectMapper.writeValueAsString(new Wrapped(range)); Wrapped result = objectMapper.readValue(json, Wrapped.class); assertEquals(range, result.r); } - + + @Test public void testUntyped() throws Exception { // Default settings do not allow possibly unsafe base type @@ -134,6 +143,7 @@ public void testUntyped() throws Exception assertEquals(Range.class, out.range.getClass()); } + @Test public void testDefaultBoundTypeNoBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3}"; @@ -146,6 +156,7 @@ public void testDefaultBoundTypeNoBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeNoBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3}"; @@ -164,6 +175,7 @@ public void testDefaultBoundTypeNoBoundTypeInformedWithClosedConfigured() throws assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testDefaultBoundTypeOnlyLowerBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3}"; @@ -176,6 +188,7 @@ public void testDefaultBoundTypeOnlyLowerBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeOnlyLowerBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3}"; @@ -193,6 +206,7 @@ public void testDefaultBoundTypeOnlyLowerBoundTypeInformedWithClosedConfigured() assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testDefaultBoundTypeOnlyUpperBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -205,6 +219,7 @@ public void testDefaultBoundTypeOnlyUpperBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeOnlyUpperBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 1, \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -222,6 +237,7 @@ public void testDefaultBoundTypeOnlyUpperBoundTypeInformedWithClosedConfigured() assertEquals(BoundType.OPEN, r.upperBoundType()); } + @Test public void testDefaultBoundTypeBothBoundTypesOpen() throws Exception { String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -235,6 +251,7 @@ public void testDefaultBoundTypeBothBoundTypesOpen() throws Exception assertEquals(BoundType.OPEN, r.upperBoundType()); } + @Test public void testDefaultBoundTypeBothBoundTypesOpenWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 1, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -253,6 +270,7 @@ public void testDefaultBoundTypeBothBoundTypesOpenWithClosedConfigured() throws assertEquals(BoundType.OPEN, r.upperBoundType()); } + @Test public void testDefaultBoundTypeBothBoundTypesClosed() throws Exception { String json = "{\"lowerEndpoint\": 1, \"lowerBoundType\": \"CLOSED\", \"upperEndpoint\": 3, \"upperBoundType\": \"CLOSED\"}"; @@ -266,6 +284,7 @@ public void testDefaultBoundTypeBothBoundTypesClosed() throws Exception assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testDefaultBoundTypeBothBoundTypesClosedWithOpenConfigured() throws Exception { String json = "{\"lowerEndpoint\": 12, \"lowerBoundType\": \"CLOSED\", \"upperEndpoint\": 33, \"upperBoundType\": \"CLOSED\"}"; @@ -284,6 +303,7 @@ public void testDefaultBoundTypeBothBoundTypesClosedWithOpenConfigured() throws assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testSnakeCaseNamingStrategy() throws Exception { String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}"; @@ -305,6 +325,7 @@ public void testSnakeCaseNamingStrategy() throws Exception } // [datatypes-collections#12] + @Test public void testRangeWithDefaultTyping() throws Exception { ObjectMapper mapper = builderWithModule() diff --git a/guava/src/test/java/tools/jackson/datatype/guava/ScalarTypesTest.java b/guava/src/test/java/tools/jackson/datatype/guava/ScalarTypesTest.java index 216ca59d..f599502e 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/ScalarTypesTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/ScalarTypesTest.java @@ -1,12 +1,18 @@ package tools.jackson.datatype.guava; -import tools.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + import com.google.common.net.InternetDomainName; +import tools.jackson.databind.ObjectMapper; + +import static org.junit.jupiter.api.Assertions.*; + public class ScalarTypesTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testInternetDomainNameSerialization() throws Exception { final String INPUT = "google.com"; @@ -14,6 +20,7 @@ public void testInternetDomainNameSerialization() throws Exception assertEquals(q(INPUT), MAPPER.writeValueAsString(name)); } + @Test public void testInternetDomainNameDeserialization() throws Exception { final String INPUT = "google.com"; diff --git a/guava/src/test/java/tools/jackson/datatype/guava/TableSerializationTest.java b/guava/src/test/java/tools/jackson/datatype/guava/TableSerializationTest.java index 132a2de3..586cd159 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/TableSerializationTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/TableSerializationTest.java @@ -1,6 +1,6 @@ package tools.jackson.datatype.guava; -import java.io.IOException; +import org.junit.jupiter.api.Test; import tools.jackson.core.JsonGenerator; import tools.jackson.core.type.TypeReference; @@ -10,6 +10,8 @@ import com.google.common.collect.ImmutableTable; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TableSerializationTest extends ModuleTestBase { private final ObjectMapper MAPPER = builderWithModule(false) @@ -117,7 +119,8 @@ else if ( !this.key2.equals(other.key2)) { } - public void testSimpleKeyImmutableTableSerde() throws IOException + @Test + public void testSimpleKeyImmutableTableSerde() throws Exception { final ImmutableTable.Builder builder = ImmutableTable.builder(); builder.put(Integer.valueOf(42), "column42", "some value 42"); @@ -139,7 +142,8 @@ public void testSimpleKeyImmutableTableSerde() throws IOException /** * This test illustrates one way to use objects as keys in Tables. */ - public void testComplexKeyImmutableTableSerde() throws IOException + @Test + public void testComplexKeyImmutableTableSerde() throws Exception { final ImmutableTable.Builder ckBuilder = ImmutableTable.builder(); ckBuilder.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/TableTest.java b/guava/src/test/java/tools/jackson/datatype/guava/TableTest.java index d3a946c0..74b4594e 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/TableTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/TableTest.java @@ -1,6 +1,10 @@ package tools.jackson.datatype.guava; -import java.io.IOException; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.TreeBasedTable; import tools.jackson.core.JsonGenerator; import tools.jackson.core.type.TypeReference; @@ -8,9 +12,7 @@ import tools.jackson.databind.*; import tools.jackson.databind.module.SimpleModule; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.ImmutableTable; -import com.google.common.collect.TreeBasedTable; +import static org.junit.jupiter.api.Assertions.*; public class TableTest extends ModuleTestBase { @@ -123,7 +125,8 @@ public int compareTo(ComplexKey complexKey) { } } - public void testSimpleKeyImmutableTableSerde() throws IOException + @Test + public void testSimpleKeyImmutableTableSerde() throws Exception { final ImmutableTable.Builder builder = ImmutableTable.builder(); builder.put(Integer.valueOf(42), "column42", "some value 42"); @@ -141,8 +144,9 @@ public void testSimpleKeyImmutableTableSerde() throws IOException ); assertEquals(simpleTable, reconstitutedTable); } - - public void testSimpleKeyHashBasedTableSerde() throws IOException + + @Test + public void testSimpleKeyHashBasedTableSerde() throws Exception { final HashBasedTable simpleTable = HashBasedTable.create(); simpleTable.put(Integer.valueOf(42), "column42", "some value 42"); @@ -158,8 +162,9 @@ public void testSimpleKeyHashBasedTableSerde() throws IOException ); assertEquals(simpleTable, reconstitutedTable); } - - public void testSimpleKeyTreeBasedTableSerde() throws IOException + + @Test + public void testSimpleKeyTreeBasedTableSerde() throws Exception { final TreeBasedTable simpleTable = TreeBasedTable.create(); simpleTable.put(Integer.valueOf(42), "column42", "some value 42"); @@ -179,7 +184,8 @@ public void testSimpleKeyTreeBasedTableSerde() throws IOException /** * This test illustrates one way to use objects as keys in Tables. */ - public void testComplexKeyImmutableTableSerde() throws IOException + @Test + public void testComplexKeyImmutableTableSerde() throws Exception { final ImmutableTable.Builder builder = ImmutableTable.builder(); builder.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); @@ -196,8 +202,9 @@ public void testComplexKeyImmutableTableSerde() throws IOException final ImmutableTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); assertEquals(complexKeyTable, reconstitutedTable); } - - public void testComplexKeyHashBasedTableSerde() throws IOException + + @Test + public void testComplexKeyHashBasedTableSerde() throws Exception { final HashBasedTable complexKeyTable = HashBasedTable.create(); complexKeyTable.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); @@ -212,8 +219,9 @@ public void testComplexKeyHashBasedTableSerde() throws IOException final HashBasedTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); assertEquals(complexKeyTable, reconstitutedTable); } - - public void testComplexKeyTreeTableSerde() throws IOException + + @Test + public void testComplexKeyTreeTableSerde() throws Exception { final TreeBasedTable complexKeyTable = TreeBasedTable.create(); complexKeyTable.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/TestPrimitives.java b/guava/src/test/java/tools/jackson/datatype/guava/TestPrimitives.java index 46be3c8d..176aec84 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/TestPrimitives.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/TestPrimitives.java @@ -1,14 +1,7 @@ package tools.jackson.datatype.guava; -import com.fasterxml.jackson.annotation.JsonTypeInfo; - -import tools.jackson.core.JacksonException; - -import tools.jackson.databind.DeserializationFeature; -import tools.jackson.databind.ObjectMapper; -import tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator; -import tools.jackson.datatype.guava.util.ImmutablePrimitiveTypes; -import tools.jackson.datatype.guava.util.PrimitiveTypes; +import java.util.Collections; +import java.util.List; import com.google.common.primitives.Booleans; import com.google.common.primitives.Bytes; @@ -28,8 +21,17 @@ import com.google.common.primitives.UnsignedLong; import com.google.common.primitives.UnsignedLongs; -import java.util.Collections; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import tools.jackson.core.JacksonException; + +import tools.jackson.databind.DeserializationFeature; +import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator; +import tools.jackson.datatype.guava.util.ImmutablePrimitiveTypes; +import tools.jackson.datatype.guava.util.PrimitiveTypes; + +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for verifying that various primitive types diff --git a/guava/src/test/java/tools/jackson/datatype/guava/TestVersions.java b/guava/src/test/java/tools/jackson/datatype/guava/TestVersions.java index 5cb41ed8..a099a6c7 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/TestVersions.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/TestVersions.java @@ -2,18 +2,25 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import tools.jackson.core.Version; import tools.jackson.core.Versioned; import tools.jackson.core.util.VersionUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + public class TestVersions extends ModuleTestBase { + @Test public void testMapperVersions() throws IOException { GuavaModule module = new GuavaModule(); assertVersion(module); } + @Test public void testPackageVersion() { assertEquals(PackageVersion.VERSION, @@ -29,7 +36,7 @@ public void testPackageVersion() private void assertVersion(Versioned vers) { final Version v = vers.version(); - assertFalse("Should find version information (got "+v+")", v.isUnknownVersion()); + assertFalse(v.isUnknownVersion(), "Should find version information (got "+v+")"); assertEquals(PackageVersion.VERSION, v); } } diff --git a/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java b/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java index 9931e5cc..3ba56d60 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java @@ -1,6 +1,8 @@ package tools.jackson.datatype.guava.fuzz; -import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ImmutableSortedMultiset; import tools.jackson.core.type.TypeReference; @@ -8,21 +10,23 @@ import tools.jackson.databind.exc.MismatchedInputException; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.collect.ImmutableSortedMultiset; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for verifying the fixes for OSS-Fuzz issues * work as expected * (see [datatypes-collections#124]). */ -public class Fuzz124_64610Test extends ModuleTestBase +public class Fuzz124_64610Test + extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testOSSFuzzIssue64610() throws Exception { final TypeReference ref = new TypeReference>() {}; - MismatchedInputException e = Assert.assertThrows( + MismatchedInputException e = assertThrows( MismatchedInputException.class, () -> MAPPER.readValue("[null]", ref)); assertTrue(e.getMessage().contains("Guava `Collection` of type ")); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java b/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java index 8f1696a3..e610991f 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java @@ -1,6 +1,6 @@ package tools.jackson.datatype.guava.fuzz; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableList; @@ -10,6 +10,8 @@ import tools.jackson.databind.exc.MismatchedInputException; import tools.jackson.datatype.guava.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying the fixes for OSS-Fuzz issues * work as expected @@ -19,10 +21,11 @@ public class Fuzz138_65117Test extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testOSSFuzzIssue65117() throws Exception { final TypeReference ref = new TypeReference>() {}; - MismatchedInputException e = Assert.assertThrows( + MismatchedInputException e = assertThrows( MismatchedInputException.class, () -> MAPPER.readValue("[\"\"s(", ref)); verifyException(e, "Guava `Collection` of type "); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalBasicTest.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalBasicTest.java index 0a8d89db..2076fb4f 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalBasicTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalBasicTest.java @@ -2,6 +2,10 @@ import java.util.*; +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; @@ -16,7 +20,7 @@ import tools.jackson.databind.ser.std.StdScalarSerializer; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; public class OptionalBasicTest extends ModuleTestBase { @@ -93,7 +97,8 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) { */ private final ObjectMapper MAPPER = mapperWithModule(); - + + @Test public void testOptionalTypeResolution() throws Exception { // With 2.6, we need to recognize it as ReferenceType @@ -102,24 +107,28 @@ public void testOptionalTypeResolution() throws Exception assertEquals(Optional.class, t.getRawClass()); assertTrue(t.isReferenceType()); } - + + @Test public void testDeserAbsent() throws Exception { Optional value = MAPPER.readValue("null", new TypeReference>() {}); assertFalse(value.isPresent()); } - + + @Test public void testDeserSimpleString() throws Exception{ Optional value = MAPPER.readValue("\"simpleString\"", new TypeReference>() {}); assertTrue(value.isPresent()); assertEquals("simpleString", value.get()); } - + + @Test public void testDeserInsideObject() throws Exception { OptionalData data = MAPPER.readValue("{\"myString\":\"simpleString\"}", OptionalData.class); assertTrue(data.myString.isPresent()); assertEquals("simpleString", data.myString.get()); } - + + @Test public void testDeserComplexObject() throws Exception { TypeReference> type = new TypeReference>() {}; Optional data = MAPPER.readValue("{\"myString\":\"simpleString\"}", type); @@ -128,6 +137,7 @@ public void testDeserComplexObject() throws Exception { assertEquals("simpleString", data.get().myString.get()); } + @Test public void testDeserGeneric() throws Exception { TypeReference>> type = new TypeReference>>() {}; Optional> data = MAPPER.readValue("{\"myData\":\"simpleString\"}", type); @@ -136,16 +146,19 @@ public void testDeserGeneric() throws Exception { assertEquals("simpleString", data.get().myData.get()); } + @Test public void testSerAbsent() throws Exception { String value = MAPPER.writeValueAsString(Optional.absent()); assertEquals("null", value); } + @Test public void testSerSimpleString() throws Exception { String value = MAPPER.writeValueAsString(Optional.of("simpleString")); assertEquals("\"simpleString\"", value); } + @Test public void testSerInsideObject() throws Exception { OptionalData data = new OptionalData(); data.myString = Optional.of("simpleString"); @@ -153,6 +166,7 @@ public void testSerInsideObject() throws Exception { assertEquals("{\"myString\":\"simpleString\"}", value); } + @Test public void testSerComplexObject() throws Exception { OptionalData data = new OptionalData(); data.myString = Optional.of("simpleString"); @@ -160,6 +174,7 @@ public void testSerComplexObject() throws Exception { assertEquals("{\"myString\":\"simpleString\"}", value); } + @Test public void testSerPropInclusionAlways() throws Exception { OptionalGenericData data = new OptionalGenericData(); data.myData = Optional.of("simpleString"); @@ -172,6 +187,7 @@ public void testSerPropInclusionAlways() throws Exception { assertEquals("{\"myData\":\"simpleString\"}", value); } + @Test public void testSerPropInclusionNonNull() throws Exception { OptionalGenericData data = new OptionalGenericData(); data.myData = Optional.of("simpleString"); @@ -184,6 +200,7 @@ public void testSerPropInclusionNonNull() throws Exception { assertEquals("{\"myData\":\"simpleString\"}", value); } + @Test public void testSerPropInclusionNonAbsent() throws Exception { OptionalGenericData data = new OptionalGenericData(); data.myData = Optional.of("simpleString"); @@ -196,6 +213,7 @@ public void testSerPropInclusionNonAbsent() throws Exception { assertEquals("{\"myData\":\"simpleString\"}", value); } + @Test public void testSerPropInclusionNonEmpty() throws Exception { OptionalGenericData data = new OptionalGenericData(); data.myData = Optional.of("simpleString"); @@ -208,6 +226,7 @@ public void testSerPropInclusionNonEmpty() throws Exception { assertEquals("{\"myData\":\"simpleString\"}", value); } + @Test public void testSerGeneric() throws Exception { OptionalGenericData data = new OptionalGenericData(); data.myData = Optional.of("simpleString"); @@ -215,6 +234,7 @@ public void testSerGeneric() throws Exception { assertEquals("{\"myData\":\"simpleString\"}", value); } + @Test public void testSerNonNull() throws Exception { OptionalData data = new OptionalData(); data.myString = Optional.absent(); @@ -226,6 +246,7 @@ public void testSerNonNull() throws Exception { assertEquals("{}", value); } + @Test public void testSerOptDefault() throws Exception { OptionalData data = new OptionalData(); data.myString = Optional.absent(); @@ -236,6 +257,7 @@ public void testSerOptDefault() throws Exception { assertEquals("{\"myString\":null}", value); } + @Test public void testSerOptNull() throws Exception { OptionalData data = new OptionalData(); data.myString = null; @@ -247,6 +269,7 @@ public void testSerOptNull() throws Exception { } // for [dataformat-guava#66] + @Test public void testSerOptDisableAsNull() throws Exception { final OptionalData data = new OptionalData(); data.myString = Optional.absent(); @@ -266,7 +289,8 @@ public void testSerOptDisableAsNull() throws Exception { .build(); assertEquals("{}", mapper.writeValueAsString(data)); } - + + @Test public void testSerOptNonEmpty() throws Exception { OptionalData data = new OptionalData(); data.myString = null; @@ -277,6 +301,7 @@ public void testSerOptNonEmpty() throws Exception { assertEquals("{}", value); } + @Test public void testSerOptNonDefault() throws Exception { OptionalData data = new OptionalData(); data.myString = null; @@ -286,7 +311,8 @@ public void testSerOptNonDefault() throws Exception { .writeValueAsString(data); assertEquals("{}", value); } - + + @Test public void testWithTypingEnabled() throws Exception { final ObjectMapper mapper = builderWithModule() @@ -302,6 +328,7 @@ public void testWithTypingEnabled() throws Exception } // [datatype-guava#17] + @Test public void testObjectId() throws Exception { final Unit input = new Unit(); @@ -315,6 +342,7 @@ public void testObjectId() throws Exception assertSame(result, base); } + @Test public void testOptionalCollection() throws Exception { ObjectMapper mapper = mapperWithModule(); TypeReference>> typeReference = @@ -331,11 +359,11 @@ public void testOptionalCollection() throws Exception { List> result = mapper.readValue(str, typeReference); assertEquals(list.size(), result.size()); for (int i = 0; i < list.size(); ++i) { - assertEquals("Entry #"+i, list.get(i), result.get(i)); + assertEquals(list.get(i), result.get(i), "Entry #"+i); } } - // [datatype-guava#81] + @Test public void testPolymorphic() throws Exception { final Container dto = new Container(); @@ -349,6 +377,7 @@ public void testPolymorphic() throws Exception assertSame(ContainedImpl.class, fromJson.contained.get().getClass()); } + @Test public void testWithCustomDeserializer() throws Exception { CaseChangingStringWrapper w = MAPPER.readValue(a2q("{'value':'FoobaR'}"), @@ -356,6 +385,7 @@ public void testWithCustomDeserializer() throws Exception assertEquals("foobar", w.value.get()); } + @Test public void testCustomSerializer() throws Exception { final String VALUE = "fooBAR"; diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromEmptyTest.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromEmptyTest.java index dd9ffb6c..ae231de6 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromEmptyTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromEmptyTest.java @@ -1,5 +1,9 @@ package tools.jackson.datatype.guava.optional; +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; @@ -10,7 +14,7 @@ import tools.jackson.databind.ObjectMapper; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; public class OptionalFromEmptyTest extends ModuleTestBase { @@ -27,12 +31,14 @@ public OptionalBeanWithEmpty(@JsonProperty("value") private final ObjectMapper MAPPER = mapperWithModule(); // [datatype-guava#48] + @Test public void testDeserNull() throws Exception { Optional value = MAPPER.readValue("\"\"", new TypeReference>() {}); assertEquals(false, value.isPresent()); } // [datatypes-collections#145] + @Test public void testDeserEmptyViaConstructor() throws Exception { OptionalBeanWithEmpty bean = MAPPER.readValue("{}", OptionalBeanWithEmpty.class); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromNullInListTest.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromNullInListTest.java index e47db2f4..0ca0fefc 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromNullInListTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalFromNullInListTest.java @@ -2,11 +2,15 @@ import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ImmutableList; + import tools.jackson.core.type.TypeReference; import tools.jackson.databind.ObjectMapper; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.collect.ImmutableList; +import static org.junit.jupiter.api.Assertions.*; public class OptionalFromNullInListTest extends ModuleTestBase { @@ -18,6 +22,7 @@ public class OptionalFromNullInListTest extends ModuleTestBase private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testImmutableListOfOptionals() throws Exception { ImmutableList> list = MAPPER.readValue("[1,null,3]", new TypeReference>>() { }); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalMergingTest.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalMergingTest.java index add9cfa7..6116ba0a 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalMergingTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalMergingTest.java @@ -1,12 +1,16 @@ package tools.jackson.datatype.guava.optional; +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; + import com.fasterxml.jackson.annotation.JsonMerge; import com.fasterxml.jackson.annotation.OptBoolean; import tools.jackson.databind.ObjectMapper; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; public class OptionalMergingTest extends ModuleTestBase { @@ -48,6 +52,7 @@ public POJO(int x, int y) { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testStringReferenceMerging() throws Exception { MergedStringReference result = MAPPER.readValue(a2q("{'value':'override'}"), @@ -55,6 +60,7 @@ public void testStringReferenceMerging() throws Exception assertEquals("override", result.value.get()); } + @Test public void testPOJOReferenceMerging() throws Exception { MergedPOJOReference result = MAPPER.readValue(a2q("{'value':{'y':-6}}"), diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalSchema83Test.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalSchema83Test.java index 19b3d404..1be3e02c 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalSchema83Test.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalSchema83Test.java @@ -2,13 +2,17 @@ import java.util.*; +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; + import com.fasterxml.jackson.annotation.*; import tools.jackson.databind.*; import tools.jackson.databind.jsonFormatVisitors.*; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; public class OptionalSchema83Test extends ModuleTestBase @@ -122,6 +126,7 @@ public void setContext(SerializationContext provider) { } } + @Test public void testOptionalTypeSchema83() throws Exception { VisitorWrapper wrapper = new VisitorWrapper(null, "", new HashSet()); mapperWithModule() diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalUnwrappedTest.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalUnwrappedTest.java index ab14d54f..fe8f807a 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalUnwrappedTest.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/OptionalUnwrappedTest.java @@ -1,10 +1,15 @@ package tools.jackson.datatype.guava.optional; +import org.junit.jupiter.api.Test; + +import com.google.common.base.Optional; + import com.fasterxml.jackson.annotation.*; + import tools.jackson.databind.*; import tools.jackson.datatype.guava.ModuleTestBase; -import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; /** * Unit test for #64, in new mode. @@ -28,6 +33,7 @@ static class OptionalParent { } // Test for "new" settings of absent != nulls, available on 2.6 and later + @Test public void testUntypedWithOptionalsNotNulls() throws Exception { final ObjectMapper mapper = mapperWithModule(false); @@ -38,6 +44,7 @@ public void testUntypedWithOptionalsNotNulls() throws Exception // Test for "old" settings (2.5 and earlier only option; available on later too) // Fixed via [datatypes-collections#136] + @Test public void testUntypedWithNullEqOptionals() throws Exception { final ObjectMapper mapper = mapperWithModule(true); diff --git a/guava/src/test/java/tools/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java b/guava/src/test/java/tools/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java index 0aba0d0c..80cf74a3 100644 --- a/guava/src/test/java/tools/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java +++ b/guava/src/test/java/tools/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java @@ -2,13 +2,18 @@ import java.util.Map; +import org.junit.jupiter.api.Test; + import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; + import com.fasterxml.jackson.annotation.*; import tools.jackson.databind.*; import tools.jackson.databind.annotation.JsonDeserialize; import tools.jackson.datatype.guava.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class TestOptionalWithPolymorphic extends ModuleTestBase { static class ContainerA { @@ -80,7 +85,8 @@ static class TypeInfoOptional { */ final ObjectMapper MAPPER = mapperWithModule(); - + + @Test public void testOptionalMapsFoo() throws Exception { ImmutableMap foo = ImmutableMap.builder() @@ -93,6 +99,7 @@ public void testOptionalMapsFoo() throws Exception { _test(MAPPER, foo); } + @Test public void testOptionalMapsBar() throws Exception { ImmutableMap bar = ImmutableMap.builder() @@ -105,6 +112,7 @@ public void testOptionalMapsBar() throws Exception { _test(MAPPER, bar); } + @Test public void testOptionalMapsBaz() throws Exception { ImmutableMap baz = ImmutableMap.builder() .put("name", "baz strategy") @@ -116,6 +124,7 @@ public void testOptionalMapsBaz() throws Exception { _test(MAPPER, baz); } + @Test public void testOptionalWithTypeAnnotation() throws Exception { AbstractOptional result = MAPPER.readValue("{\"value\" : 5}", @@ -138,6 +147,7 @@ private void _test(ObjectMapper m, Map map) throws Exception assertNotNull(objB); } + @Test public void testOptionalPropagatesTypeInfo() throws Exception { TypeInfoOptional data = new TypeInfoOptional(); diff --git a/hppc/src/test/java/tools/jackson/datatype/hppc/TestVersions.java b/hppc/src/test/java/tools/jackson/datatype/hppc/TestVersions.java index 329d02da..ccef158f 100644 --- a/hppc/src/test/java/tools/jackson/datatype/hppc/TestVersions.java +++ b/hppc/src/test/java/tools/jackson/datatype/hppc/TestVersions.java @@ -2,10 +2,13 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; public class TestVersions extends ModuleTestBase { + @Test public void testMapperVersions() throws IOException { HppcModule module = new HppcModule();