From 7169b999468ab906968282f8639a18df8d34b72b Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Thu, 23 Jan 2025 02:39:48 +0900 Subject: [PATCH] Migrate `guava` module tests to `JUnit 5` (#178) --- guava/pom.xml | 11 +++-- .../guava/CacheDeserializationTest.java | 11 +++++ .../guava/CacheSerializationTest.java | 20 ++++++++ .../datatype/guava/EmptyCollectionsTest.java | 6 +++ .../datatype/guava/FluentIterableTest.java | 7 +++ .../jackson/datatype/guava/HashCodeTest.java | 6 +++ .../datatype/guava/HostAndPortTest.java | 7 +++ .../guava/ImmutableContainersTest.java | 23 +++++++-- .../jackson/datatype/guava/IterablesTest.java | 6 +++ .../datatype/guava/JavaSerializableTest.java | 10 +++- .../JsonDeserContentConverter92Test.java | 6 +++ .../datatype/guava/ModuleTestBase.java | 4 +- .../datatype/guava/MultiMap104Test.java | 6 +++ .../MultiMapOrderMpEntriesByKeys7Test.java | 10 +++- .../jackson/datatype/guava/MultimapsTest.java | 33 +++++++++++-- .../jackson/datatype/guava/MultisetsTest.java | 24 ++++++++-- .../guava/RangeDeserializer102Test.java | 9 ++++ .../guava/RangeDeserializer188Test.java | 11 +++++ .../jackson/datatype/guava/RangeSetTest.java | 7 +++ .../jackson/datatype/guava/RangeTest.java | 25 +++++++++- .../datatype/guava/ScalarTypesTest.java | 6 +++ .../jackson/datatype/guava/TableTest.java | 18 +++++-- .../jackson/datatype/guava/TestVersions.java | 8 +++- .../guava/fuzz/Fuzz124_64610Test.java | 10 ++-- .../guava/fuzz/Fuzz138_65117Test.java | 7 ++- .../guava/optional/OptionalBasicTest.java | 47 +++++++++++++++---- .../guava/optional/OptionalFromEmptyTest.java | 5 ++ .../optional/OptionalFromNullInListTest.java | 5 ++ .../guava/optional/OptionalMergingTest.java | 6 +++ .../guava/optional/OptionalSchema83Test.java | 5 ++ .../guava/optional/OptionalUnwrappedTest.java | 6 +++ .../optional/TestOptionalWithPolymorphic.java | 12 ++++- .../jackson/datatype/hppc/TestVersions.java | 3 ++ 33 files changed, 338 insertions(+), 42 deletions(-) diff --git a/guava/pom.xml b/guava/pom.xml index f02d0119..f6ab2b56 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -67,10 +67,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/test/java/com/fasterxml/jackson/datatype/guava/CacheDeserializationTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheDeserializationTest.java index 0b111b6c..d0b4bd2c 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheDeserializationTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheDeserializationTest.java @@ -10,10 +10,13 @@ import com.google.common.base.Optional; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.Objects; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying deserialization of Guava's {@link Cache} type. * @@ -66,6 +69,7 @@ private enum MyEnum { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testGuavaCacheApi() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); // Cache does not allow null key @@ -81,6 +85,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(); @@ -93,6 +98,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); @@ -109,6 +115,7 @@ public void testCacheDeserRoundTrip() throws Exception { } // [datatype-collections#96] + @Test public void testCacheSerialization() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); cache.put(1L, 1); @@ -132,6 +139,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(); @@ -155,11 +163,13 @@ static class CacheWrapper { private Cache cache = CacheBuilder.newBuilder().build(); } + @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(); @@ -179,6 +189,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/com/fasterxml/jackson/datatype/guava/CacheSerializationTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheSerializationTest.java index a82c53ed..8577d46a 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheSerializationTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/CacheSerializationTest.java @@ -7,10 +7,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. * @@ -188,6 +191,7 @@ public String toString() { private final ObjectMapper ORDERED_MAPPER = mapperWithModule().enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); + @Test public void testGuavaCacheApi() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); // Cache does not allow null key @@ -203,6 +207,7 @@ public void testGuavaCacheApi() throws Exception { } catch (NullPointerException e) {} } + @Test public void testCacheSerialization() throws Exception { // Create a Guava Cache Cache cache = CacheBuilder.newBuilder().build(); @@ -214,6 +219,7 @@ public void testCacheSerialization() throws Exception { ORDERED_MAPPER.writeValueAsString(cache)); } + @Test public void testCacheSerializationIgnoreProperties() throws Exception { CacheContainerWithIgnores container = new CacheContainerWithIgnores(); @@ -222,6 +228,7 @@ public void testCacheSerializationIgnoreProperties() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithBean() throws Exception { CacheContainerWithBean container = new CacheContainerWithBean(); @@ -230,6 +237,7 @@ public void testCacheSerializationWithBean() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithList() throws Exception { CacheContainerWithList container = new CacheContainerWithList(); @@ -238,6 +246,7 @@ public void testCacheSerializationWithList() throws Exception { ORDERED_MAPPER.writeValueAsString(container)); } + @Test public void testCacheSerializationWithEmptyCache() throws Exception { Cache cache = CacheBuilder.newBuilder().build(); @@ -246,6 +255,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"); @@ -255,6 +265,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"); @@ -267,12 +278,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); @@ -286,6 +299,7 @@ public void testCacheSerializationWithTypeReference() throws Exception { assertEquals(expected, mapperSer); } + @Test public void testOrderByKeyViaProperty() throws Exception { CacheOrderingBean input = new CacheOrderingBean("c", "b", "a"); @@ -294,6 +308,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()); @@ -308,6 +323,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")); @@ -330,6 +346,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); @@ -337,6 +354,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'}}")); @@ -351,6 +369,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"); @@ -362,6 +381,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/com/fasterxml/jackson/datatype/guava/EmptyCollectionsTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/EmptyCollectionsTest.java index 533fe755..c942cf85 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/EmptyCollectionsTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/EmptyCollectionsTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; @@ -7,6 +9,8 @@ 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/com/fasterxml/jackson/datatype/guava/FluentIterableTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/FluentIterableTest.java index 0b0267ed..aafb3b31 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/FluentIterableTest.java +++ b/guava/src/test/java/com/fasterxml/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 com.fasterxml.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,11 +39,13 @@ 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); diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HashCodeTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HashCodeTest.java index bd58a3b4..998ed368 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HashCodeTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HashCodeTest.java @@ -1,14 +1,19 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.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/com/fasterxml/jackson/datatype/guava/HostAndPortTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HostAndPortTest.java index 248a8c55..beb6499d 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HostAndPortTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/HostAndPortTest.java @@ -1,14 +1,19 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.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/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java index 3e87130a..1d8a2004 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java +++ b/guava/src/test/java/com/fasterxml/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 com.fasterxml.jackson.core.type.TypeReference; @@ -13,6 +15,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}) @@ -42,6 +46,7 @@ public Holder(Object v) { * Immutable types can actually be serialized as regular collections, without * problems. */ + @Test public void testWithoutSerializers() throws Exception { ImmutableList list = ImmutableList.builder() @@ -68,6 +73,7 @@ public void testWithoutSerializers() throws Exception /** * Deserialization will fail, however. */ + @Test public void testWithoutDeserializersFail() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -115,6 +121,7 @@ private void _verifyImmutableException(InvalidDefinitionException e, Class ty /********************************************************************** */ + @Test public void testImmutableList() throws Exception { ImmutableList list = MAPPER.readValue("[1,2,3]", new TypeReference>() { }); @@ -124,6 +131,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]", @@ -139,6 +147,7 @@ public void testImmutableSet() throws Exception assertEquals(0, set.size()); } + @Test public void testImmutableSetFromSingle() throws Exception { ObjectMapper mapper = mapperWithModule() @@ -148,7 +157,8 @@ public void testImmutableSetFromSingle() throws Exception assertEquals(1, set.size()); assertTrue(set.contains("abc")); } - + + @Test public void testTypedImmutableset() throws Exception { ImmutableSet set; @@ -181,6 +191,7 @@ public void testTypedImmutableset() throws Exception assertEquals(0, ((ImmutableSet) result.value).size()); } + @Test public void testImmutableSortedSet() throws Exception { ImmutableSortedSet set = MAPPER.readValue("[5,1,2]", new TypeReference>() { }); @@ -190,7 +201,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>() { }); @@ -208,6 +220,7 @@ public void testImmutableMap() throws Exception assertEquals(1, map.size()); } + @Test public void testTypedImmutableMap() throws Exception { ImmutableMap map; @@ -239,7 +252,8 @@ public void testTypedImmutableMap() throws Exception } assertEquals(0, ((ImmutableMap) result.value).size()); } - + + @Test public void testImmutableSortedMap() throws Exception { ImmutableSortedMap map = MAPPER.readValue("{\"12\":true,\"4\":false}", new TypeReference>() { }); @@ -247,7 +261,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>() { }); diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/IterablesTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/IterablesTest.java index ddd2e77f..8dcc7df7 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/IterablesTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/IterablesTest.java @@ -1,11 +1,15 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.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/com/fasterxml/jackson/datatype/guava/JavaSerializableTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JavaSerializableTest.java index e559300f..fcacebf7 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JavaSerializableTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JavaSerializableTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Optional; @@ -11,8 +13,11 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import static org.junit.jupiter.api.Assertions.*; + public class JavaSerializableTest extends ModuleTestBase { + @Test public void testSerializable() throws IOException, ClassNotFoundException { ObjectMapper mapper = mapperWithModule(); @@ -24,6 +29,7 @@ public void testSerializable() throws IOException, ClassNotFoundException { assertTrue(set.contains("abc")); } + @Test public void testSerializableConfigureAbsentsAsNull() throws IOException, ClassNotFoundException { ObjectMapper mapper = mapperWithModule(true); @@ -54,8 +60,8 @@ private ObjectMapper serializeAndDeserialize(ObjectMapper mapper) throws IOExcep Object deserializedObject = inputStream.readObject(); //validate the object - assertTrue("Deserialized object should be an instance of ObjectMapper", - ObjectMapper.class == deserializedObject.getClass()); + assertTrue(ObjectMapper.class == deserializedObject.getClass(), + "Deserialized object should be an instance of ObjectMapper"); return (ObjectMapper) deserializedObject; } diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JsonDeserContentConverter92Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JsonDeserContentConverter92Test.java index fbc1b9d1..c2b5c917 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JsonDeserContentConverter92Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/JsonDeserContentConverter92Test.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -11,6 +13,8 @@ import java.util.Arrays; import java.util.List; +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 +92,7 @@ static class GuavaImmutableBiMapHolder { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testJsonSerialize() throws Exception { String jsonStr = a2q("{'list':[2,4]}"); @@ -95,6 +100,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/com/fasterxml/jackson/datatype/guava/ModuleTestBase.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ModuleTestBase.java index 728f76ee..2780478e 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ModuleTestBase.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ModuleTestBase.java @@ -5,7 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -public abstract class ModuleTestBase extends junit.framework.TestCase +import static org.junit.jupiter.api.Assertions.fail; + +public abstract class ModuleTestBase { protected ModuleTestBase() { } diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMap104Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMap104Test.java index 591fa4dd..99469b58 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMap104Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMap104Test.java @@ -1,9 +1,13 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.*; import com.google.common.collect.ArrayListMultimap; +import static org.junit.jupiter.api.Assertions.*; + public class MultiMap104Test extends ModuleTestBase { // [datatypes-collections#104] @@ -15,12 +19,14 @@ static class Outside104 { private final ObjectMapper MAPPER = mapperWithModule(); // [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/com/fasterxml/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java index b4dcef7b..40acc6d5 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultiMapOrderMpEntriesByKeys7Test.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -9,7 +11,7 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; // [jackson-datatype-collections#7]: [Guava] Add support for WRITE_SORTED_MAP_ENTRIES public class MultiMapOrderMpEntriesByKeys7Test extends ModuleTestBase { @@ -50,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); @@ -65,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); @@ -81,6 +85,7 @@ public void testMultimapSerializeUnorderedByKey() throws Exception { } + @Test public void testMultimapSerializeWithNullKeyFailure() throws Exception { final Multimap multimap = HashMultimap.create(); multimap.put("c_key", 1); @@ -98,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); @@ -113,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); @@ -139,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/com/fasterxml/jackson/datatype/guava/MultimapsTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultimapsTest.java index addec4d5..b9c8c745 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultimapsTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultimapsTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -17,6 +19,8 @@ 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. * @@ -100,6 +104,7 @@ static class SampleMultiMapTest { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testMultimap() throws Exception { _testMultimap(TreeMultimap.create(), true, @@ -140,6 +145,7 @@ private void _testMultimap(Multimap map0, boolean fullyOrdered, String EXPE } } + @Test public void testMultimapIssue3() throws Exception { Multimap m1 = TreeMultimap.create(); @@ -170,6 +176,7 @@ public void testMultimapIssue3() throws Exception assertEquals(2, javaMap.size()); } + @Test public void testEnumKey() throws Exception { final TypeReference> type = new TypeReference>() {}; @@ -185,12 +192,14 @@ public void testEnumKey() throws Exception } // [Issue#41] + @Test public void testEmptyMapExclusion() throws Exception { String json = MAPPER.writeValueAsString(new MultiMapWrapper()); assertEquals("{}", json); } + @Test public void testNullHandling() throws Exception { Multimap input = ArrayListMultimap.create(); @@ -199,7 +208,8 @@ public void testNullHandling() throws Exception assertEquals(aposToQuotes("{'empty':[null]}"), json); } - // [datatypes-collections#27]: + // [datatypes-collections#27]: + @Test public void testWithReferenceType() throws Exception { String json = "{\"a\" : [5.0, null, 6.0]}"; @@ -230,6 +240,7 @@ public void testForwardingSortedSetMultimap() throws IOException { } */ + @Test public void testImmutableSetMultimap() throws IOException { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { @@ -237,6 +248,7 @@ public void testImmutableSetMultimap() throws IOException { assertTrue(map instanceof ImmutableSetMultimap); } + @Test public void testHashMultimap() throws IOException { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { @@ -244,6 +256,7 @@ public void testHashMultimap() throws IOException { assertTrue(map instanceof HashMultimap); } + @Test public void testLinkedHashMultimap() throws IOException { SetMultimap map = _verifyMultiMapRead(new TypeReference>() { @@ -275,6 +288,7 @@ private SetMultimap _verifyMultiMapRead(TypeReference type) /********************************************************************** */ + @Test public void testArrayListMultimap() throws IOException { ListMultimap map = listBasedHelper(new TypeReference>() { @@ -282,6 +296,7 @@ public void testArrayListMultimap() throws IOException { assertTrue(map instanceof ArrayListMultimap); } + @Test public void testLinkedListMultimap() throws IOException { ListMultimap map = listBasedHelper(new TypeReference>() { @@ -289,6 +304,7 @@ public void testLinkedListMultimap() throws IOException { assertTrue(map instanceof LinkedListMultimap); } + @Test public void testMultimapWithIgnores() throws IOException { assertEquals("{\"map\":{\"a\":[\"foo\"]}}", MAPPER.writeValueAsString(new MultiMapWithIgnores())); @@ -306,6 +322,7 @@ private ListMultimap listBasedHelper(TypeReference type) thro return map; } + @Test public void testIssue67() throws IOException { ImmutableSetMultimap map = MAPPER.readValue( @@ -325,6 +342,7 @@ public void testIssue67() throws IOException } // [Issue#25] + @Test public void testDefaultSetMultiMap() throws IOException { @SuppressWarnings("unchecked") SetMultimap map = (SetMultimap) MAPPER @@ -332,7 +350,8 @@ public void testDefaultSetMultiMap() throws IOException { SetMultimap.class); assertTrue(map instanceof LinkedHashMultimap); } - + + @Test public void testPolymorphicValue() throws IOException { ImmutableMultimapWrapper input = new ImmutableMultimapWrapper(ImmutableMultimap.of("add", new AddOp(3, 2), "mul", new MulOp(4, 6))); @@ -341,7 +360,8 @@ public void testPolymorphicValue() throws IOException { ImmutableMultimapWrapper output = MAPPER.readValue(json, ImmutableMultimapWrapper.class); assertEquals(input, output); } - + + @Test public void testFromSingleValue() throws Exception { ObjectMapper mapper = mapperWithModule() @@ -351,7 +371,8 @@ public void testFromSingleValue() throws Exception assertEquals(1, sampleTest.map.get("test").size()); } - + + @Test public void testFromMultiValueWithSingleValueOptionEnabled() throws Exception { ObjectMapper mapper = mapperWithModule() @@ -366,7 +387,8 @@ public void testFromMultiValueWithSingleValueOptionEnabled() throws Exception // Make sure that our Value is still a String not [String] assertEquals(sampleTest.map.entries().iterator().next().getValue(), "val"); } - + + @Test public void testFromMultiValueWithNoSingleValueOptionEnabled() throws Exception { SampleMultiMapTest sampleTest = MAPPER.readValue("{\"map\":{\"test\":[\"val\"],\"test1\":[\"val1\",\"val2\"]}}", @@ -401,6 +423,7 @@ ArrayListMultimap mapValue() { } // [datatype-collections#96] + @Test public void testMultimapIssue96() throws Exception { // First the original, properties case: diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java index 5e29a28d..3fbd5255 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.*; @@ -7,6 +9,8 @@ import com.fasterxml.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. * @@ -24,6 +28,7 @@ public class MultisetsTest extends ModuleTestBase * Multi-sets can actually be serialized as regular collections, without * problems. */ + @Test public void testWithoutSerializers() throws Exception { @@ -38,6 +43,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(); @@ -61,32 +67,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>() { }); } @@ -112,6 +125,7 @@ private > void _testMultiset(TypeReference typeRef } } + @Test public void testFromSingle() throws Exception { ObjectMapper mapper = mapperWithModule() diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer102Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer102Test.java index e2067c21..e1486b72 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer102Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer102Test.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategies; @@ -8,6 +10,8 @@ import com.google.common.collect.BoundType; import com.google.common.collect.Range; +import static org.junit.jupiter.api.Assertions.*; + public class RangeDeserializer102Test extends ModuleTestBase { private final ObjectMapper MAPPER_DEFAULT = mapperWithModule(); @@ -16,6 +20,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\"}"; @@ -37,11 +42,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"); @@ -63,6 +70,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 { @@ -74,6 +82,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/com/fasterxml/jackson/datatype/guava/RangeDeserializer188Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer188Test.java index 2a776149..c58b23ca 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer188Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeDeserializer188Test.java @@ -3,6 +3,8 @@ import java.time.Duration; import java.time.LocalDate; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; @@ -12,6 +14,8 @@ import com.google.common.collect.Range; +import static org.junit.jupiter.api.Assertions.*; + // Test for [dataformats-collections#118] public class RangeDeserializer188Test extends ModuleTestBase { @@ -51,6 +55,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)"); @@ -67,6 +72,7 @@ public void testRangeSerializationToString() throws Exception } // [dataformats-collections#135] + @Test public void testIntRangeDeserializationFromBracketNotation() throws Exception { testIntRangeDeserialization("{\"r\":\"(1..10)\"}", openRange); @@ -79,12 +85,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)\"}", @@ -92,6 +100,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 { /* @@ -101,6 +110,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 { /* @@ -109,6 +119,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/com/fasterxml/jackson/datatype/guava/RangeSetTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeSetTest.java index bb4831c7..e96e9a13 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeSetTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeSetTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; @@ -13,10 +15,13 @@ import java.io.IOException; +import static org.junit.jupiter.api.Assertions.*; + public class RangeSetTest extends ModuleTestBase { private final ObjectMapper MAPPER = mapperWithModule(); + @Test public void testSerializeDeserialize() throws IOException { final RangeSet rangeSet = TreeRangeSet.create(); @@ -35,6 +40,7 @@ public void testSerializeDeserialize() throws IOException { } + @Test public void testSerializeDeserializeImmutableRangeSet() throws Exception { final ImmutableRangeSet rangeSet = ImmutableRangeSet.builder() .add(Range.closedOpen(1, 2)) @@ -51,6 +57,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/com/fasterxml/jackson/datatype/guava/RangeTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeTest.java index d67800f6..a32b2aa0 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/RangeTest.java @@ -16,6 +16,9 @@ import com.google.common.collect.BoundType; import com.google.common.collect.Range; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests to verify serialization of Guava {@link Range}s. @@ -45,6 +48,7 @@ public Wrapped() { } * or Guava's implementation of Range changes. * @throws Exception */ + @Test public void testSerializationWithoutModule() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -53,6 +57,7 @@ public void testSerializationWithoutModule() throws Exception assertEquals("{\"empty\":false}", json); } + @Test public void testSerialization() throws Exception { testSerialization(MAPPER, RangeFactory.open(1, 10)); @@ -67,6 +72,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(); @@ -82,6 +88,7 @@ public void testSerializationWithPropertyNamingStrategy() throws Exception testSerialization(mappper, RangeFactory.singleton(1)); } + @Test public void testWrappedSerialization() throws Exception { testSerializationWrapped(MAPPER, RangeFactory.open(1, 10)); @@ -94,7 +101,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)); @@ -118,7 +126,8 @@ private void testSerializationWrapped(ObjectMapper objectMapper, Range Wrapped result = objectMapper.readValue(json, Wrapped.class); assertEquals(range, result.r); } - + + @Test public void testUntyped() throws Exception { String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(new Untyped(RangeFactory.open(1, 10))); @@ -127,6 +136,7 @@ public void testUntyped() throws Exception assertEquals(Range.class, out.range.getClass()); } + @Test public void testDefaultBoundTypeNoBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3}"; @@ -139,6 +149,7 @@ public void testDefaultBoundTypeNoBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeNoBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3}"; @@ -157,6 +168,7 @@ public void testDefaultBoundTypeNoBoundTypeInformedWithClosedConfigured() throws assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testDefaultBoundTypeOnlyLowerBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3}"; @@ -169,6 +181,7 @@ public void testDefaultBoundTypeOnlyLowerBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeOnlyLowerBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3}"; @@ -186,6 +199,7 @@ public void testDefaultBoundTypeOnlyLowerBoundTypeInformedWithClosedConfigured() assertEquals(BoundType.CLOSED, r.upperBoundType()); } + @Test public void testDefaultBoundTypeOnlyUpperBoundTypeInformed() throws Exception { String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -198,6 +212,7 @@ public void testDefaultBoundTypeOnlyUpperBoundTypeInformed() throws Exception } } + @Test public void testDefaultBoundTypeOnlyUpperBoundTypeInformedWithClosedConfigured() throws Exception { String json = "{\"lowerEndpoint\": 1, \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}"; @@ -215,6 +230,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\"}"; @@ -228,6 +244,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\"}"; @@ -246,6 +263,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\"}"; @@ -259,6 +277,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\"}"; @@ -277,6 +296,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\"}"; @@ -298,6 +318,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/com/fasterxml/jackson/datatype/guava/ScalarTypesTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ScalarTypesTest.java index 9835e993..771ab53d 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ScalarTypesTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ScalarTypesTest.java @@ -1,12 +1,17 @@ package com.fasterxml.jackson.datatype.guava; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.net.InternetDomainName; +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 +19,7 @@ public void testInternetDomainNameSerialization() throws Exception assertEquals(quote(INPUT), MAPPER.writeValueAsString(name)); } + @Test public void testInternetDomainNameDeserialization() throws Exception { final String INPUT = "google.com"; diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java index 1172f5d5..830db880 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java @@ -2,6 +2,8 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.type.TypeReference; @@ -12,6 +14,8 @@ import com.google.common.collect.ImmutableTable; import com.google.common.collect.TreeBasedTable; +import static org.junit.jupiter.api.Assertions.*; + public class TableTest extends ModuleTestBase { private final ObjectMapper MAPPER = builderWithModule(false) @@ -124,6 +128,7 @@ public int compareTo(ComplexKey complexKey) { } } + @Test public void testSimpleKeyImmutableTableSerde() throws IOException { final ImmutableTable.Builder builder = ImmutableTable.builder(); @@ -142,7 +147,8 @@ public void testSimpleKeyImmutableTableSerde() throws IOException ); assertEquals(simpleTable, reconstitutedTable); } - + + @Test public void testSimpleKeyHashBasedTableSerde() throws IOException { final HashBasedTable simpleTable = HashBasedTable.create(); @@ -159,7 +165,8 @@ public void testSimpleKeyHashBasedTableSerde() throws IOException ); assertEquals(simpleTable, reconstitutedTable); } - + + @Test public void testSimpleKeyTreeBasedTableSerde() throws IOException { final TreeBasedTable simpleTable = TreeBasedTable.create(); @@ -180,6 +187,7 @@ public void testSimpleKeyTreeBasedTableSerde() throws IOException /** * This test illustrates one way to use objects as keys in Tables. */ + @Test public void testComplexKeyImmutableTableSerde() throws IOException { final ImmutableTable.Builder builder = ImmutableTable.builder(); @@ -197,7 +205,8 @@ public void testComplexKeyImmutableTableSerde() throws IOException final ImmutableTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); assertEquals(complexKeyTable, reconstitutedTable); } - + + @Test public void testComplexKeyHashBasedTableSerde() throws IOException { final HashBasedTable complexKeyTable = HashBasedTable.create(); @@ -213,7 +222,8 @@ public void testComplexKeyHashBasedTableSerde() throws IOException final HashBasedTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); assertEquals(complexKeyTable, reconstitutedTable); } - + + @Test public void testComplexKeyTreeTableSerde() throws IOException { final TreeBasedTable complexKeyTable = TreeBasedTable.create(); diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TestVersions.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TestVersions.java index 2233c489..d9cd2997 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TestVersions.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TestVersions.java @@ -2,18 +2,24 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.core.Versioned; import com.fasterxml.jackson.core.util.VersionUtil; +import static org.junit.jupiter.api.Assertions.*; + 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 +35,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/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java index a8802e6b..07d0d7f2 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz124_64610Test.java @@ -1,6 +1,6 @@ package com.fasterxml.jackson.datatype.guava.fuzz; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.type.TypeReference; @@ -10,19 +10,23 @@ 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/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java index 32a2fd61..e576429e 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/fuzz/Fuzz138_65117Test.java @@ -1,6 +1,6 @@ package com.fasterxml.jackson.datatype.guava.fuzz; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.type.TypeReference; @@ -10,6 +10,8 @@ import com.google.common.collect.ImmutableList; +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/com/fasterxml/jackson/datatype/guava/optional/OptionalBasicTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalBasicTest.java index 71c269c5..aa1b079c 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalBasicTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalBasicTest.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; @@ -20,6 +22,8 @@ import com.fasterxml.jackson.datatype.guava.testutil.NoCheckSubTypeValidator; import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; + public class OptionalBasicTest extends ModuleTestBase { public static final class OptionalData { @@ -99,7 +103,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 @@ -108,24 +113,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); @@ -134,6 +143,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); @@ -142,16 +152,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"); @@ -159,6 +172,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"); @@ -166,6 +180,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"); @@ -177,6 +192,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"); @@ -188,6 +204,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"); @@ -199,6 +216,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"); @@ -210,6 +228,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"); @@ -217,6 +236,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(); @@ -233,6 +254,7 @@ public void testSerOptDefault() throws Exception { assertEquals("{\"myString\":null}", value); } + @Test public void testSerOptNull() throws Exception { OptionalData data = new OptionalData(); data.myString = null; @@ -241,6 +263,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(); @@ -264,7 +287,8 @@ public void testSerOptDisableAsNull() throws Exception { .setSerializationInclusion(JsonInclude.Include.NON_ABSENT); assertEquals("{}", mapper.writeValueAsString(data)); } - + + @Test public void testSerOptNonEmpty() throws Exception { OptionalData data = new OptionalData(); data.myString = null; @@ -272,13 +296,15 @@ public void testSerOptNonEmpty() throws Exception { assertEquals("{}", value); } + @Test public void testSerOptNonDefault() throws Exception { OptionalData data = new OptionalData(); data.myString = null; String value = mapperWithModule().setSerializationInclusion(JsonInclude.Include.NON_DEFAULT).writeValueAsString(data); assertEquals("{}", value); } - + + @Test public void testWithTypingEnabled() throws Exception { final ObjectMapper objectMapper = builderWithModule() @@ -296,6 +322,7 @@ public void testWithTypingEnabled() throws Exception } // [datatype-guava#17] + @Test public void testObjectId() throws Exception { final Unit input = new Unit(); @@ -310,6 +337,7 @@ public void testObjectId() throws Exception } // [Issue#37] + @Test public void testOptionalCollection() throws Exception { ObjectMapper mapper = new ObjectMapper().registerModule(new GuavaModule()); @@ -327,11 +355,12 @@ 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(); @@ -345,6 +374,7 @@ public void testPolymorphic() throws Exception assertSame(ContainedImpl.class, fromJson.contained.get().getClass()); } + @Test public void testWithCustomDeserializer() throws Exception { CaseChangingStringWrapper w = MAPPER.readValue(aposToQuotes("{'value':'FoobaR'}"), @@ -352,6 +382,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/com/fasterxml/jackson/datatype/guava/optional/OptionalFromEmptyTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromEmptyTest.java index 6989e2e1..2f062557 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromEmptyTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromEmptyTest.java @@ -11,6 +11,9 @@ import com.fasterxml.jackson.datatype.guava.ModuleTestBase; import com.google.common.base.Optional; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class OptionalFromEmptyTest extends ModuleTestBase { @@ -27,12 +30,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/com/fasterxml/jackson/datatype/guava/optional/OptionalFromNullInListTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromNullInListTest.java index 96172988..6f9ab03f 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromNullInListTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromNullInListTest.java @@ -2,11 +2,15 @@ import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.ModuleTestBase; import com.google.common.collect.ImmutableList; +import static org.junit.jupiter.api.Assertions.*; + public class OptionalFromNullInListTest extends ModuleTestBase { /* @@ -17,6 +21,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/com/fasterxml/jackson/datatype/guava/optional/OptionalMergingTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalMergingTest.java index 39909c96..b95c64f6 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalMergingTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalMergingTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.guava.optional; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonMerge; import com.fasterxml.jackson.annotation.OptBoolean; @@ -8,6 +10,8 @@ import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; + public class OptionalMergingTest extends ModuleTestBase { static class MergedStringReference @@ -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(aposToQuotes("{'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(aposToQuotes("{'value':{'y':-6}}"), diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalSchema83Test.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalSchema83Test.java index ae117c9b..f8961d96 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalSchema83Test.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalSchema83Test.java @@ -3,11 +3,15 @@ import java.util.*; import com.google.common.base.Optional; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonFormatVisitors.*; import com.fasterxml.jackson.datatype.guava.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class OptionalSchema83Test extends ModuleTestBase { @@ -120,6 +124,7 @@ public void setProvider(SerializerProvider provider) { } } + @Test public void testOptionalTypeSchema83() throws Exception { VisitorWrapper wrapper = new VisitorWrapper(null, "", new HashSet()); mapperWithModule() diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalUnwrappedTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalUnwrappedTest.java index 18cb8126..9d614117 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalUnwrappedTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalUnwrappedTest.java @@ -1,10 +1,14 @@ package com.fasterxml.jackson.datatype.guava.optional; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.datatype.guava.ModuleTestBase; import com.google.common.base.Optional; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit test for #64, in new mode. */ @@ -27,6 +31,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); @@ -37,6 +42,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/com/fasterxml/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java index 312d8207..3b52d03e 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/TestOptionalWithPolymorphic.java +++ b/guava/src/test/java/com/fasterxml/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 com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.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/com/fasterxml/jackson/datatype/hppc/TestVersions.java b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java index f0f25b19..3f487584 100644 --- a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java +++ b/hppc/src/test/java/com/fasterxml/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 HppcTestBase { + @Test public void testMapperVersions() throws IOException { HppcModule module = new HppcModule();