diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetter3394Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetter3394Test.java index 2f88657161..d1ef3bb88a 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetter3394Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetter3394Test.java @@ -1,12 +1,18 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.annotation.JsonAnySetter; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.node.ObjectNode; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.a2q; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; + // for [databind#3394] -public class AnySetter3394Test extends BaseMapTest +public class AnySetter3394Test { static class AnySetter3394Bean { public int id; @@ -23,6 +29,7 @@ static class AnySetter3394Bean { private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testAnySetterWithJsonNode() throws Exception { final String DOC = a2q("{'test':3,'nullable':null,'id':42,'value':true}"); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterTest.java index c7f6b543d3..1693453be4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterTest.java @@ -2,18 +2,22 @@ import java.util.*; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * Unit tests for verifying that {@link JsonAnySetter} annotation * works as expected. */ public class AnySetterTest - extends BaseMapTest { static class MapImitator { @@ -259,6 +263,7 @@ static class IdentityDTO349 { private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testSimpleMapImitation() throws Exception { MapImitator mapHolder = MAPPER.readValue @@ -274,6 +279,7 @@ public void testSimpleMapImitation() throws Exception assertEquals(Integer.valueOf(3), l.get(2)); } + @Test public void testAnySetterDisable() throws Exception { try { @@ -286,16 +292,18 @@ public void testAnySetterDisable() throws Exception } + @Test public void testSimpleTyped() throws Exception { MapImitatorWithValue mapHolder = MAPPER.readValue ("{ \"a\" : [ 3, -1 ], \"b\" : [ ] }", MapImitatorWithValue.class); Map result = mapHolder._map; assertEquals(2, result.size()); - assertEquals(new int[] { 3, -1 }, result.get("a")); - assertEquals(new int[0], result.get("b")); + assertArrayEquals(new int[] { 3, -1 }, result.get("a")); + assertArrayEquals(new int[0], result.get("b")); } + @Test public void testBrokenWithDoubleAnnotations() throws Exception { try { @@ -307,20 +315,23 @@ public void testBrokenWithDoubleAnnotations() throws Exception } } + @Test public void testIgnored() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); _testIgnorals(mapper); } + @Test public void testIgnoredPart2() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); _testIgnorals(mapper); } + @Test public void testProblem744() throws Exception { Bean744 bean = MAPPER.readValue("{\"name\":\"Bob\"}", Bean744.class); @@ -329,6 +340,7 @@ public void testProblem744() throws Exception assertEquals("Bob", bean.additionalProperties.get("name")); } + @Test public void testIssue797() throws Exception { String json = MAPPER.writeValueAsString(new Bean797BaseImpl()); @@ -336,6 +348,7 @@ public void testIssue797() throws Exception } // [Issue#337] + @Test public void testPolymorphic() throws Exception { PolyAnyBean input = new PolyAnyBean(); @@ -353,6 +366,7 @@ public void testPolymorphic() throws Exception assertEquals("xyz", ((Impl) ob).value); } + @Test public void testJsonAnySetterOnMap() throws Exception { JsonAnySetterOnMap result = MAPPER.readValue("{\"id\":2,\"name\":\"Joe\", \"city\":\"New Jersey\"}", JsonAnySetterOnMap.class); @@ -361,6 +375,7 @@ public void testJsonAnySetterOnMap() throws Exception { assertEquals("New Jersey", result.other.get("city")); } + @Test public void testJsonAnySetterOnNullMap() throws Exception { final String DOC = a2q("{'id':2,'name':'Joe', 'city':'New Jersey'}"); JsonAnySetterOnNullMap result = MAPPER.readValue(DOC, @@ -391,9 +406,10 @@ public void testJsonAnySetterOnNullMap() throws Exception { ); // [databind#349] + @Test public void testUnwrappedWithAny() throws Exception { - final ObjectMapper mapper = objectMapper(); + final ObjectMapper mapper = newJsonMapper(); Bean349 value = mapper.readValue(UNWRAPPED_JSON_349, Bean349.class); assertNotNull(value); assertEquals(3, value.x); @@ -402,9 +418,10 @@ public void testUnwrappedWithAny() throws Exception } // [databind#349] + @Test public void testUnwrappedWithAnyAsUpdate() throws Exception { - final ObjectMapper mapper = objectMapper(); + final ObjectMapper mapper = newJsonMapper(); Bean349 bean = mapper.readerFor(Bean349.class) .withValueToUpdate(new Bean349()) .readValue(UNWRAPPED_JSON_349); @@ -414,9 +431,10 @@ public void testUnwrappedWithAnyAsUpdate() throws Exception } // [databind#1035] + @Test public void testGenericAnySetter() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); Map stringGenericMap = new HashMap(); stringGenericMap.put("testStringKey", 5); @@ -432,8 +450,8 @@ public void testGenericAnySetter() throws Exception assertNotNull(stringGeneric); assertEquals(stringGeneric.getStaticallyMappedProperty(), "Test"); for(Map.Entry entry : stringGeneric.getDynamicallyMappedProperties().entrySet()) { - assertTrue("A key in MyGeneric is not an String.", entry.getKey() instanceof String); - assertTrue("A value in MyGeneric is not an Integer.", entry.getValue() instanceof Integer); + assertTrue(entry.getKey() instanceof String, "A key in MyGeneric is not an String."); + assertTrue(entry.getValue() instanceof Integer, "A value in MyGeneric is not an Integer."); } assertEquals(stringGeneric.getDynamicallyMappedProperties(), stringGenericMap); @@ -441,9 +459,9 @@ public void testGenericAnySetter() throws Exception assertEquals(integerGeneric.getStaticallyMappedProperty(), "Test2"); for(Map.Entry entry : integerGeneric.getDynamicallyMappedProperties().entrySet()) { Object key = entry.getKey(); - assertEquals("A key in MyGeneric is not an Integer.", Integer.class, key.getClass()); + assertEquals(Integer.class, key.getClass(), "A key in MyGeneric is not an Integer."); Object value = entry.getValue(); - assertEquals("A value in MyGeneric is not an Integer.", Integer.class, value.getClass()); + assertEquals(Integer.class, value.getClass(), "A value in MyGeneric is not an Integer."); } assertEquals(integerGeneric.getDynamicallyMappedProperties(), integerGenericMap); } diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/CyclicTypesDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/CyclicTypesDeserTest.java index 3a7d31b60e..247b853c1b 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/CyclicTypesDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/CyclicTypesDeserTest.java @@ -1,10 +1,16 @@ package com.fasterxml.jackson.databind.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * Simple unit tests to verify that it is possible to handle * potentially cyclic structures, as long as object graph itself @@ -12,7 +18,6 @@ * trees and DAGs. */ public class CyclicTypesDeserTest - extends BaseMapTest { static class Bean { @@ -62,6 +67,7 @@ static class Selfie405 { private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testLinked() throws Exception { Bean first = MAPPER.readValue @@ -77,6 +83,7 @@ public void testLinked() throws Exception assertNull(last._next); } + @Test public void testLinkedGeneric() throws Exception { StringLink link = MAPPER.readValue("{\"next\":null}", StringLink.class); @@ -84,6 +91,7 @@ public void testLinkedGeneric() throws Exception assertNull(link.next); } + @Test public void testCycleWith2Classes() throws Exception { LinkA a = MAPPER.readValue("{\"next\":{\"a\":null}}", LinkA.class); @@ -93,6 +101,7 @@ public void testCycleWith2Classes() throws Exception } // [Issue#405]: Should be possible to ignore cyclic ref + @Test public void testIgnoredCycle() throws Exception { Selfie405 self1 = new Selfie405(1); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/DeserializerFactoryTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/DeserializerFactoryTest.java index 82c988a734..21aca5fc1d 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/DeserializerFactoryTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/DeserializerFactoryTest.java @@ -2,17 +2,24 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.fail; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.sharedMapper; + // Tests for [databind#2539] for checking whether given (raw) type has explicit // deserializer associated -public class DeserializerFactoryTest extends BaseMapTest +public class DeserializerFactoryTest { private final ObjectMapper MAPPER = sharedMapper(); static class POJO2539 { } // [databind#2539]: check existence of deserializer for type + @Test public void testJDKScalarDeserializerExistence() throws Exception { // First verify some basic types @@ -34,6 +41,7 @@ public void testJDKScalarDeserializerExistence() throws Exception // _verifyIsFound(java.util.Object.class); } + @Test public void testJDKContainerDeserializerExistence() throws Exception { // Both general and specific container types should be considered supported @@ -48,6 +56,7 @@ public void testJDKContainerDeserializerExistence() throws Exception _verifyIsFound(HashSet.class); } + @Test public void testJDKArraysOfExistence() throws Exception { // Similarly, array types of all supported types should be allowed @@ -57,6 +66,7 @@ public void testJDKArraysOfExistence() throws Exception _verifyIsFound(UUID[].class); } + @Test public void testNoDeserTypes() throws Exception { // Types for which we should NOT have explicit deserializer diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/GenericCollectionDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/GenericCollectionDeserTest.java index fe958e658b..e9c2ab3be7 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/GenericCollectionDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/GenericCollectionDeserTest.java @@ -2,14 +2,19 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil.StringWrapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; @SuppressWarnings("serial") public class GenericCollectionDeserTest - extends BaseMapTest { static class ListSubClass extends ArrayList { } @@ -41,6 +46,7 @@ protected static class BooleanElement { /** * Verifying that sub-classing works ok wrt generics information */ + @Test public void testListSubClass() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -59,6 +65,7 @@ public void testListSubClass() throws Exception */ // Verifying that sub-classing works ok wrt generics information + @Test public void testAnnotatedLStringist() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -69,6 +76,7 @@ public void testAnnotatedLStringist() throws Exception assertEquals("...", ((StringWrapper) ob).str); } + @Test public void testAnnotatedBooleanList() throws Exception { ObjectMapper mapper = new ObjectMapper(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/GenericValuesDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/GenericValuesDeserTest.java index ed11126f40..240e31a978 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/GenericValuesDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/GenericValuesDeserTest.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.databind.deser; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; + public class GenericValuesDeserTest - extends BaseMapTest { static abstract class BaseNumberBean { @@ -52,9 +57,10 @@ public boolean equals(Object o) { /*************************************************** */ + @Test public void testSimpleNumberBean() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); NumberBean result = mapper.readValue("{\"number\":17}", NumberBean.class); assertEquals(17, result._number); } @@ -62,9 +68,10 @@ public void testSimpleNumberBean() throws Exception /** * Unit test for verifying fix to [JACKSON-109]. */ + @Test public void testGenericWrapper() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); Wrapper result = mapper.readValue ("{\"value\": { \"x\" : 13 } }", new TypeReference>() { }); @@ -77,9 +84,10 @@ public void testGenericWrapper() throws Exception assertEquals(13, bean.x); } + @Test public void testGenericWrapperWithSingleElementArray() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); Wrapper result = mapper.readValue @@ -96,9 +104,10 @@ public void testGenericWrapperWithSingleElementArray() throws Exception // Test for verifying that we can use different // type bindings for individual generic types. + @Test public void testMultipleWrappers() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); // First, numeric wrapper Wrapper result = mapper.readValue @@ -117,9 +126,10 @@ public void testMultipleWrappers() throws Exception } //[databind#381] + @Test public void testMultipleWrappersSingleValueArray() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); // First, numeric wrapper @@ -141,9 +151,10 @@ public void testMultipleWrappersSingleValueArray() throws Exception /** * Unit test for verifying fix to [JACKSON-109]. */ + @Test public void testArrayOfGenericWrappers() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); Wrapper[] result = mapper.readValue ("[ {\"value\": { \"x\" : 9 } } ]", new TypeReference[]>() { }); @@ -159,9 +170,10 @@ public void testArrayOfGenericWrappers() throws Exception } // [Issue#381] + @Test public void testArrayOfGenericWrappersSingleValueArray() throws Exception { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = newJsonMapper(); mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); Wrapper[] result = mapper.readValue diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/IgnoreWithDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/IgnoreWithDeserTest.java index 5854baad10..cc7b69f77d 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/IgnoreWithDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/IgnoreWithDeserTest.java @@ -1,16 +1,21 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.IgnoredPropertyException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * This unit test suite that tests use of {@link JsonIgnore} * annotation with deserialization. */ public class IgnoreWithDeserTest - extends BaseMapTest { // Class for testing {@link JsonIgnore} annotations with setters final static class SizeClassIgnore @@ -45,6 +50,7 @@ final static class NoYOrZ private final ObjectMapper MAPPER = objectMapper(); + @Test public void testSimpleIgnore() throws Exception { SizeClassIgnore result = MAPPER.readValue("{ \"x\":1, \"y\" : 2 }", @@ -54,6 +60,7 @@ public void testSimpleIgnore() throws Exception assertEquals(0, result._y); } + @Test public void testFailOnIgnore() throws Exception { ObjectReader r = MAPPER.readerFor(NoYOrZ.class); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/IncludeWithDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/IncludeWithDeserTest.java index 8bc0b615bf..ee37b5f6b6 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/IncludeWithDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/IncludeWithDeserTest.java @@ -1,22 +1,23 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; + +import java.util.*; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.IgnoredPropertyException; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; /** * This unit test suite that tests use of {@link com.fasterxml.jackson.annotation.JsonIncludeProperties} * annotation with deserialization. */ public class IncludeWithDeserTest - extends BaseMapTest { @JsonIncludeProperties({"y", "z"}) static class OnlyYAndZ @@ -109,6 +110,7 @@ public void anySet(String field, AnySetterObjectId value) private final ObjectMapper MAPPER = objectMapper(); + @Test public void testSimpleInclude() throws Exception { OnlyYAndZ result = MAPPER.readValue( @@ -119,6 +121,7 @@ public void testSimpleInclude() throws Exception assertEquals(3, result._z); } + @Test public void testIncludeIgnoredAndUnrecognizedField() throws Exception { ObjectReader r = MAPPER.readerFor(OnlyY.class); @@ -152,7 +155,7 @@ public void testIncludeIgnoredAndUnrecognizedField() throws Exception assertEquals(4, result.y); } - + @Test public void testMergeInclude() throws Exception { OnlyYWrapperForOnlyYAndZ onlyY = MAPPER.readValue( @@ -164,6 +167,7 @@ public void testMergeInclude() throws Exception assertEquals(0, onlyY.onlyY._z); } + @Test public void testListInclude() throws Exception { IncludeForListValuesY result = MAPPER.readValue( @@ -174,6 +178,7 @@ public void testListInclude() throws Exception assertEquals(0, result.onlyYs.get(0)._z); } + @Test public void testMapWrapper() throws Exception { MapWrapper result = MAPPER.readValue(a2q("{'value': {'a': 2, 'b': 3}}"), MapWrapper.class); @@ -181,6 +186,7 @@ public void testMapWrapper() throws Exception assertFalse(result.value.containsKey("b")); } + @Test public void testMyMap() throws Exception { MyMap result = MAPPER.readValue(a2q("{'a': 2, 'b': 3}"), MyMap.class); @@ -188,6 +194,7 @@ public void testMyMap() throws Exception assertFalse(result.containsKey("b")); } + @Test public void testForwardReferenceAnySetterComboWithInclude() throws Exception { String json = a2q("{'@id':1, 'foo':2, 'foo2':2, 'bar':{'@id':2, 'foo':1}}"); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/InnerClassDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/InnerClassDeserTest.java index a89aabf7a0..fc6603dd2d 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/InnerClassDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/InnerClassDeserTest.java @@ -1,9 +1,13 @@ package com.fasterxml.jackson.databind.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.*; -public class InnerClassDeserTest extends BaseMapTest +import static org.junit.jupiter.api.Assertions.*; + +public class InnerClassDeserTest { static class Dog { @@ -32,6 +36,7 @@ public class Brain { /********************************************************** */ + @Test public void testSimpleNonStaticInner() throws Exception { // Let's actually verify by first serializing, then deserializing back diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/Issue3913DeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/Issue3913DeserTest.java index d7425cf93a..b979b0da19 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/Issue3913DeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/Issue3913DeserTest.java @@ -1,15 +1,20 @@ package com.fasterxml.jackson.databind.deser; +import java.util.List; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.jsonMapperBuilder; -public class Issue3913DeserTest extends BaseMapTest +public class Issue3913DeserTest { // [databind#3913] static class MyResponse { @@ -74,6 +79,7 @@ public void setMissingInJson(String missingInJson) { } // [databind#3913] + @Test public void testDeserialization() throws JsonProcessingException { ObjectMapper mapper = jsonMapperBuilder() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/JacksonTypesDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/JacksonTypesDeserTest.java index abf6d5b8e2..8739bfa5ae 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/JacksonTypesDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/JacksonTypesDeserTest.java @@ -2,6 +2,8 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.io.ContentReference; import com.fasterxml.jackson.databind.*; @@ -9,14 +11,18 @@ import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.TokenBuffer; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * Unit tests for those Jackson types we want to ensure can be deserialized. */ public class JacksonTypesDeserTest - extends com.fasterxml.jackson.databind.BaseMapTest { private final ObjectMapper MAPPER = sharedMapper(); + @Test public void testJsonLocation() throws Exception { // note: source reference is untyped, only String guaranteed to work @@ -37,6 +43,7 @@ public void testJsonLocation() throws Exception } // doesn't really belong here but... + @Test public void testJsonLocationProps() { JsonLocation loc = new JsonLocation(null, -1, -1, 100, 13); @@ -49,6 +56,7 @@ public void testJsonLocationProps() loc.hashCode(); } + @Test public void testJavaType() throws Exception { TypeFactory tf = TypeFactory.defaultInstance(); @@ -65,6 +73,7 @@ public void testJavaType() throws Exception * Verify that {@link TokenBuffer} can be properly deserialized * automatically, using the "standard" JSON sample document */ + @Test public void testTokenBufferWithSample() throws Exception { // First, try standard sample doc: @@ -74,6 +83,7 @@ public void testTokenBufferWithSample() throws Exception } @SuppressWarnings("resource") + @Test public void testTokenBufferWithSequence() throws Exception { // and then sequence of other things @@ -117,6 +127,7 @@ public void testTokenBufferWithSequence() throws Exception private final static int RECURSION_2398 = 25000; // [databind#2398] + @Test public void testDeeplyNestedArrays() throws Exception { JsonFactory jsonFactory = JsonFactory.builder() @@ -131,6 +142,7 @@ public void testDeeplyNestedArrays() throws Exception } } + @Test public void testDeeplyNestedObjects() throws Exception { JsonFactory jsonFactory = JsonFactory.builder() diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/MergePolymorphicTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/MergePolymorphicTest.java index 4a44504b67..7109c38a1c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/MergePolymorphicTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/MergePolymorphicTest.java @@ -1,15 +1,19 @@ package com.fasterxml.jackson.databind.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonMerge; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; - -import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -public class MergePolymorphicTest extends BaseMapTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MergePolymorphicTest +{ static class Root { @JsonMerge @@ -36,12 +40,14 @@ static class ChildB extends Child { .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .build(); + @Test public void testPolymorphicNewObject() throws Exception { Root root = MAPPER.readValue("{\"child\": { \"@type\": \"ChildA\", \"name\": \"I'm child A\" }}", Root.class); assertTrue(root.child instanceof ChildA); assertEquals("I'm child A", ((ChildA) root.child).name); } + @Test public void testPolymorphicFromNullToNewObject() throws Exception { Root root = new Root(); MAPPER.readerForUpdating(root).readValue("{\"child\": { \"@type\": \"ChildA\", \"name\": \"I'm the new name\" }}"); @@ -49,6 +55,7 @@ public void testPolymorphicFromNullToNewObject() throws Exception { assertEquals("I'm the new name", ((ChildA) root.child).name); } + @Test public void testPolymorphicFromObjectToNull() throws Exception { Root root = new Root(); ChildA childA = new ChildA(); @@ -58,6 +65,7 @@ public void testPolymorphicFromObjectToNull() throws Exception { assertTrue(root.child == null); } + @Test public void testPolymorphicPropertyCanBeMerged() throws Exception { Root root = new Root(); ChildA childA = new ChildA(); @@ -68,6 +76,7 @@ public void testPolymorphicPropertyCanBeMerged() throws Exception { assertEquals("I'm the new name", ((ChildA) root.child).name); } + @Test public void testPolymorphicPropertyTypeCanNotBeChanged() throws Exception { Root root = new Root(); ChildA childA = new ChildA(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/NoStaticsDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/NoStaticsDeserTest.java index 136619cfcd..724b3999dc 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/NoStaticsDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/NoStaticsDeserTest.java @@ -1,15 +1,17 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Tests for checking that static methods are not recognized as accessors * for properties */ public class NoStaticsDeserTest - extends BaseMapTest { static class Bean { @@ -26,6 +28,7 @@ static class Bean /********************************************************** */ + @Test public void testSimpleIgnore() throws Exception { ObjectMapper m = new ObjectMapper(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/NullHandlingTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/NullHandlingTest.java index 2e3f038b5c..076e5cf04c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/NullHandlingTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/NullHandlingTest.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.JsonSubTypes.Type; import com.fasterxml.jackson.core.*; @@ -12,7 +14,12 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; -public class NullHandlingTest extends BaseMapTest +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; + +public class NullHandlingTest { static class FunnyNullDeserializer extends JsonDeserializer { @@ -93,6 +100,7 @@ enum EnumMapTestEnum { /********************************************************************** */ + @Test public void testNull() throws Exception { // null doesn't really have a type, fake by assuming Object @@ -100,6 +108,7 @@ public void testNull() throws Exception assertNull(result); } + @Test public void testAnySetterNulls() throws Exception { ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule("test", Version.unknownVersion()); @@ -125,6 +134,7 @@ public void testAnySetterNulls() throws Exception { assertEquals("funny", result.getAny().get(fieldName)); } + @Test public void testCustomRootNulls() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -145,6 +155,7 @@ public void testCustomRootNulls() throws Exception } // [databind#407] + @Test public void testListOfNulls() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -170,6 +181,7 @@ public void testListOfNulls() throws Exception } // Test for [#407] + @Test public void testMapOfNulls() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -193,23 +205,25 @@ public void testMapOfNulls() throws Exception } // [databind#1601] + @Test public void testPolymorphicDataNull() throws Exception { String typeA = "{\"name\":\"TypeAData\", \"type\":\"TypeA\", \"proxy\":{\"aValue\":\"This works!\"}}"; RootData typeAData = MAPPER.readValue(typeA, RootData.class); - assertEquals("No value for aValue!?", "This works!", ((TypeA) typeAData.proxy).aValue); + assertEquals("This works!", ((TypeA) typeAData.proxy).aValue, "No value for aValue!?"); String typeB = "{\"name\":\"TypeBData\", \"type\":\"TypeB\", \"proxy\":{\"bValue\":\"This works too!\"}}"; RootData typeBData = MAPPER.readValue(typeB, RootData.class); - assertEquals("No value for bValue!?", "This works too!", ((TypeB) typeBData.proxy).bValue); + assertEquals("This works too!", ((TypeB) typeBData.proxy).bValue, "No value for bValue!?"); String typeBNull = "{\"name\":\"TypeBData\", \"type\":\"TypeB\", \"proxy\": null}"; RootData typeBNullData = MAPPER.readValue(typeBNull, RootData.class); - assertNull("Proxy should be null!", typeBNullData.proxy); + assertNull(typeBNullData.proxy, "Proxy should be null!"); } // Test for [databind#3227] + @Test public void testContentsNullFailForMaps() throws Exception { try { @@ -228,6 +242,7 @@ public void testContentsNullFailForMaps() throws Exception } // Test for [databind#3227] + @Test public void testContentsNullFailForCollections() throws Exception { try { @@ -262,6 +277,7 @@ public void testContentsNullFailForCollections() throws Exception } // Test for [databind#3227] + @Test public void testContentsNullFailForArrays() throws Exception { try { diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/ObjectOrArrayDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/ObjectOrArrayDeserTest.java index 2a80b8adf4..51280bca59 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/ObjectOrArrayDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/ObjectOrArrayDeserTest.java @@ -2,11 +2,16 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.ObjectMapper; -public class ObjectOrArrayDeserTest extends BaseMapTest +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; + +public class ObjectOrArrayDeserTest { public static class SomeObject { public String someField; @@ -31,23 +36,26 @@ public ArrayOrObject(SomeObject object) { private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testObjectCase() throws Exception { ArrayOrObject arrayOrObject = MAPPER.readValue("{}", ArrayOrObject.class); - assertNull("expected objects field to be null", arrayOrObject.objects); - assertNotNull("expected object field not to be null", arrayOrObject.object); + assertNull(arrayOrObject.objects, "expected objects field to be null"); + assertNotNull(arrayOrObject.object, "expected object field not to be null"); } + @Test public void testEmptyArrayCase() throws Exception { ArrayOrObject arrayOrObject = MAPPER.readValue("[]", ArrayOrObject.class); - assertNotNull("expected objects field not to be null", arrayOrObject.objects); - assertTrue("expected objects field to be an empty list", arrayOrObject.objects.isEmpty()); - assertNull("expected object field to be null", arrayOrObject.object); + assertNotNull(arrayOrObject.objects, "expected objects field not to be null"); + assertTrue(arrayOrObject.objects.isEmpty(), "expected objects field to be an empty list"); + assertNull(arrayOrObject.object, "expected object field to be null"); } + @Test public void testNotEmptyArrayCase() throws Exception { ArrayOrObject arrayOrObject = MAPPER.readValue("[{}, {}]", ArrayOrObject.class); - assertNotNull("expected objects field not to be null", arrayOrObject.objects); - assertEquals("expected objects field to have size 2", 2, arrayOrObject.objects.size()); - assertNull("expected object field to be null", arrayOrObject.object); + assertNotNull(arrayOrObject.objects, "expected objects field not to be null"); + assertEquals(2, arrayOrObject.objects.size(), "expected objects field to have size 2"); + assertNull(arrayOrObject.object, "expected object field to be null"); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/OverloadedMethodsDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/OverloadedMethodsDeserTest.java index 15266adc21..60211f5c40 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/OverloadedMethodsDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/OverloadedMethodsDeserTest.java @@ -2,17 +2,23 @@ import java.util.*; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; + /** * Unit tests related to handling of overloaded methods. * and specifically addressing problems [JACKSON-189] * and [JACKSON-739] */ public class OverloadedMethodsDeserTest - extends BaseMapTest { static class BaseListBean { @@ -71,6 +77,7 @@ public void setA(LinkedList a) { } * It should be ok to overload with specialized * version; more specific method should be used. */ + @Test public void testSpecialization() throws Exception { ArrayListBean bean = MAPPER.readValue @@ -87,6 +94,7 @@ public void testSpecialization() throws Exception * As per [JACKSON-255], should also allow more general overriding, * as long as there are no in-class conflicts. */ + @Test public void testOverride() throws Exception { WasNumberBean bean = MAPPER.readValue @@ -96,6 +104,7 @@ public void testOverride() throws Exception } // for [JACKSON-739] + @Test public void testConflictResolution() throws Exception { Overloaded739 bean = MAPPER.readValue @@ -113,6 +122,7 @@ public void testConflictResolution() throws Exception /** * For genuine setter conflict, an exception is to be thrown. */ + @Test public void testSetterConflict() throws Exception { try { diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/PropertyAliasTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/PropertyAliasTest.java index 11aa248dde..1463b1515b 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/PropertyAliasTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/PropertyAliasTest.java @@ -1,16 +1,19 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.annotation.JsonAlias; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.databind.BaseMapTest; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -public class PropertyAliasTest extends BaseMapTest +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.a2q; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; + +public class PropertyAliasTest { static class AliasBean { @JsonAlias({ "nm", "Name" }) @@ -83,6 +86,7 @@ public void setName(String name) { private final ObjectMapper MAPPER = newJsonMapper(); // [databind#1029] + @Test public void testSimpleAliases() throws Exception { AliasBean bean; @@ -109,6 +113,7 @@ public void testSimpleAliases() throws Exception assertEquals(37, bean._xyz); } + @Test public void testAliasWithPolymorphic() throws Exception { PolyWrapperForAlias value = MAPPER.readValue(a2q( @@ -121,6 +126,7 @@ public void testAliasWithPolymorphic() throws Exception } // [databind#2378] + @Test public void testAliasInFactoryMethod() throws Exception { AliasBean2378 bean = MAPPER.readValue(a2q( @@ -131,6 +137,7 @@ public void testAliasInFactoryMethod() throws Exception } // [databind#2669] + @Test public void testCaseInsensitiveAliases() throws Exception { ObjectMapper mapper = JsonMapper.builder() @@ -148,6 +155,7 @@ static class FixedOrderAliasBean { public String value; } + @Test public void testAliasDeserializedToLastMatchingKey_ascendingKeys() throws Exception { String ascendingOrderInput = a2q( "{\"a\": \"a-value\", " + @@ -158,6 +166,7 @@ public void testAliasDeserializedToLastMatchingKey_ascendingKeys() throws Except assertEquals("c-value", ascObj.value); } + @Test public void testAliasDeserializedToLastMatchingKey_descendingKeys() throws Exception { String descendingOrderInput = a2q( "{\"c\": \"c-value\", " + @@ -173,6 +182,7 @@ static class AscendingOrderAliasBean { public String value; } + @Test public void testAliasDeserializedToLastMatchingKey_ascendingAliases() throws Exception { String input = a2q( "{\"a\": \"a-value\", " + @@ -188,6 +198,7 @@ static class DescendingOrderAliasBean { public String value; } + @Test public void testAliasDeserializedToLastMatchingKey_descendingAliases() throws Exception { String input = a2q( "{\"a\": \"a-value\", " + @@ -206,6 +217,7 @@ static class AliasTestBeanA { public String fullName; } + @Test public void testAliasFallBackToField() throws Exception { AliasTestBeanA obj = MAPPER.readValue(a2q( "{\"fullName\": \"Faster Jackson\", \"name\":\"Jackson\"}" diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestAnnotationUsing.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestAnnotationUsing.java index 2da8149d72..afda0f7237 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestAnnotationUsing.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestAnnotationUsing.java @@ -3,19 +3,22 @@ import java.io.*; import java.util.*; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Unit test suite that tests "usingXxx" properties of * {@link JsonDeserialize} annotation. */ @SuppressWarnings("serial") public class TestAnnotationUsing - extends BaseMapTest { /* /********************************************************************** @@ -126,6 +129,7 @@ public Object deserializeKey(String key, DeserializationContext ctxt) // Unit test to verify that {@link JsonDeserialize#using} annotation works // when applied to a class + @Test public void testClassDeserializer() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -135,6 +139,7 @@ public void testClassDeserializer() throws Exception // Unit test to verify that {@link JsonDeserialize#using} annotation works // when applied to a Method + @Test public void testMethodDeserializer() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -153,6 +158,7 @@ public void testMethodDeserializer() throws Exception /********************************************************************** */ + @Test public void testArrayContentUsing() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -169,6 +175,7 @@ public void testArrayContentUsing() throws Exception assertEquals(3, ((ValueClass) obs[2])._a); } + @Test public void testListContentUsing() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -185,6 +192,7 @@ public void testListContentUsing() throws Exception assertEquals(3, ((ValueClass) obs.get(2))._a); } + @Test public void testMapContentUsing() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -199,6 +207,7 @@ public void testMapContentUsing() throws Exception assertEquals(2, ((ValueClass) map.get("b"))._a); } + @Test public void testMapKeyUsing() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -213,6 +222,7 @@ public void testMapKeyUsing() throws Exception } // @since 1.8 + @Test public void testRootValueWithCustomKey() throws Exception { ObjectMapper m = new ObjectMapper(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java index 5e5f5d40f0..fc84beeb64 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java @@ -2,6 +2,8 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.core.*; @@ -9,6 +11,12 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.jsonMapperBuilder; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.q; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.IntWrapper; + /** * This unit test suite tests use of basic Annotations for * bean deserialization; ones that indicate (non-constructor) @@ -16,7 +24,6 @@ */ @SuppressWarnings("serial") public class TestBasicAnnotations - extends BaseMapTest { /// Class for testing {@link JsonProperty} annotations final static class SizeClassSetter @@ -125,6 +132,7 @@ public int[] deserialize(JsonParser jp, DeserializationContext ctxt) private final ObjectMapper MAPPER = new ObjectMapper(); + @Test public void testSimpleSetter() throws Exception { SizeClassSetter result = MAPPER.readValue @@ -137,6 +145,7 @@ public void testSimpleSetter() throws Exception } // Test for checking [JACKSON-64] + @Test public void testSimpleSetter2() throws Exception { SizeClassSetter2 result = MAPPER.readValue("{ \"x\": -3 }", @@ -145,6 +154,7 @@ public void testSimpleSetter2() throws Exception } // Checking parts of [JACKSON-120] + @Test public void testSimpleSetter3() throws Exception { SizeClassSetter3 result = MAPPER.readValue @@ -157,6 +167,7 @@ public void testSimpleSetter3() throws Exception * Test for verifying that super-class setters are used as * expected. */ + @Test public void testSetterInheritance() throws Exception { BeanSubClass result = MAPPER.readValue @@ -167,6 +178,7 @@ public void testSetterInheritance() throws Exception assertEquals(3, result._z); } + @Test public void testImpliedProperty() throws Exception { BeanWithDeserialize bean = MAPPER.readValue("{\"a\":3}", BeanWithDeserialize.class); @@ -175,6 +187,7 @@ public void testImpliedProperty() throws Exception } // [databind#442] + @Test public void testIssue442PrivateUnwrapped() throws Exception { Issue442Bean bean = MAPPER.readValue("{\"i\":5}", Issue442Bean.class); @@ -187,6 +200,7 @@ public void testIssue442PrivateUnwrapped() throws Exception /********************************************************** */ + @Test public void testAnnotationsDisabled() throws Exception { // first: verify that annotation introspection is enabled by default @@ -203,6 +217,7 @@ public void testAnnotationsDisabled() throws Exception assertEquals(0, bean.value); } + @Test public void testEnumsWhenDisabled() throws Exception { ObjectMapper m = new ObjectMapper(); @@ -215,6 +230,7 @@ public void testEnumsWhenDisabled() throws Exception assertEquals(Alpha.B, m.readValue(q("B"), Alpha.class)); } + @Test public void testNoAccessOverrides() throws Exception { ObjectMapper m = jsonMapperBuilder() diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestBeanDeserializer.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestBeanDeserializer.java index e036db64f6..51bed012af 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestBeanDeserializer.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestBeanDeserializer.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.*; @@ -15,8 +17,13 @@ import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.databind.type.MapType; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + @SuppressWarnings("serial") -public class TestBeanDeserializer extends BaseMapTest +public class TestBeanDeserializer { static abstract class Abstract { public int x; @@ -330,6 +337,7 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) * abstract type should fail (if there is no way to determine * actual type information for the concrete type to use) */ + @Test public void testAbstractFailure() throws Exception { try { @@ -339,6 +347,7 @@ public void testAbstractFailure() throws Exception verifyException(e, "cannot construct"); } } + @Test public void testPropertyRemoval() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -349,6 +358,7 @@ public void testPropertyRemoval() throws Exception assertEquals("a", bean.a); } + @Test public void testDeserializerReplacement() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -359,6 +369,7 @@ public void testDeserializerReplacement() throws Exception assertEquals("bar", bean.b); } + @Test public void testIssue476() throws Exception { final String JSON = "{\"value1\" : {\"name\" : \"fruit\", \"value\" : \"apple\"}, \"value2\" : {\"name\" : \"color\", \"value\" : \"red\"}}"; @@ -372,6 +383,7 @@ public void testIssue476() throws Exception } // [databind#120] + @Test public void testModifyArrayDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -382,6 +394,7 @@ public void testModifyArrayDeserializer() throws Exception assertEquals("foo", result[0]); } + @Test public void testModifyCollectionDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -393,6 +406,7 @@ public void testModifyCollectionDeserializer() throws Exception assertEquals("foo", result.get(0)); } + @Test public void testModifyMapDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -404,6 +418,7 @@ public void testModifyMapDeserializer() throws Exception assertEquals("foo", result.get("a")); } + @Test public void testModifyEnumDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -414,6 +429,7 @@ public void testModifyEnumDeserializer() throws Exception assertEquals("foo", result); } + @Test public void testModifyKeyDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -429,6 +445,7 @@ public void testModifyKeyDeserializer() throws Exception * Test to verify that even standard deserializers will result in `modifyDeserializer` * getting appropriately called. */ + @Test public void testModifyStdScalarDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -447,6 +464,7 @@ public JsonDeserializer modifyDeserializer(DeserializationConfig config, assertEquals("ABCDEF", result); } + @Test public void testAddOrReplacePropertyIsUsedOnDeserialization() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Issue1912Module()); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java index 3050e1a011..7a0a883ec7 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java @@ -3,15 +3,23 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.exc.StreamConstraintsException; -import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil.DoubleWrapper; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; -public class TestBigNumbers extends BaseMapTest +public class TestBigNumbers { static class BigDecimalWrapper { BigDecimal number; @@ -56,6 +64,7 @@ private ObjectMapper newJsonMapperWithUnlimitedNumberSizeSupport() { return JsonMapper.builder(jsonFactory).build(); } + @Test public void testDouble() throws Exception { try { @@ -66,6 +75,7 @@ public void testDouble() throws Exception } } + @Test public void testDoubleUnlimited() throws Exception { DoubleWrapper dw = @@ -73,6 +83,7 @@ public void testDoubleUnlimited() throws Exception assertNotNull(dw); } + @Test public void testBigDecimal() throws Exception { try { @@ -83,6 +94,7 @@ public void testBigDecimal() throws Exception } } + @Test public void testBigDecimalUnlimited() throws Exception { BigDecimalWrapper bdw = @@ -91,6 +103,7 @@ public void testBigDecimalUnlimited() throws Exception assertNotNull(bdw); } + @Test public void testBigInteger() throws Exception { try { @@ -101,6 +114,7 @@ public void testBigInteger() throws Exception } } + @Test public void testBigIntegerUnlimited() throws Exception { BigIntegerWrapper bdw = diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestCachingOfDeser.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestCachingOfDeser.java index b4e6d68773..541fa768d0 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestCachingOfDeser.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestCachingOfDeser.java @@ -4,15 +4,19 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + @SuppressWarnings("serial") -public class TestCachingOfDeser extends BaseMapTest +public class TestCachingOfDeser { // For [databind#735] public static class TestMapNoCustom { @@ -57,6 +61,7 @@ public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOE // Ok: first, use custom-annotated instance first, then standard + @Test public void testCustomMapCaching1() throws Exception { @@ -71,6 +76,7 @@ public void testCustomMapCaching1() throws Exception } // And then standard first, custom next + @Test public void testCustomMapCaching2() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -84,6 +90,7 @@ public void testCustomMapCaching2() throws Exception } // Ok: first, use custom-annotated instance first, then standard + @Test public void testCustomListCaching1() throws Exception { ObjectMapper mapper = new ObjectMapper(); TestListWithCustom listC = mapper.readValue(LIST_INPUT, TestListWithCustom.class); @@ -96,6 +103,7 @@ public void testCustomListCaching1() throws Exception { } // First custom-annotated, then standard + @Test public void testCustomListCaching2() throws Exception { ObjectMapper mapper = new ObjectMapper(); TestListNoCustom listStd = mapper.readValue(LIST_INPUT, TestListNoCustom.class); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestConcurrency.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestConcurrency.java index 9869da542a..e73364c54a 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestConcurrency.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestConcurrency.java @@ -2,14 +2,18 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Testing for NPE due to race condition. */ -public class TestConcurrency extends BaseMapTest +public class TestConcurrency { @JsonDeserialize(using=CustomBeanDeserializer.class) static class Bean @@ -60,6 +64,7 @@ public void resolve(DeserializationContext ctxt) /********************************************** */ + @Test public void testDeserializerResolution() throws Exception { /* Let's repeat couple of times, just to be sure; thread timing is not diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java index 239e8e7248..6e1de87351 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java @@ -4,6 +4,8 @@ import java.lang.annotation.*; import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -18,12 +20,15 @@ import com.fasterxml.jackson.databind.util.NameTransformer; import com.fasterxml.jackson.databind.util.StdConverter; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * Test to check that customizations work as expected. */ @SuppressWarnings("serial") public class TestCustomDeserializers - extends BaseMapTest { static class DummyDeserializer extends StdDeserializer @@ -400,6 +405,7 @@ protected JsonDeserializer newDelegatingInstance(JsonDeserializer newDeleg private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testCustomBeanDeserializer() throws Exception { String json = "{\"beans\":[{\"c\":{\"a\":10,\"b\":20},\"d\":\"hello, tatu\"}]}"; @@ -441,6 +447,7 @@ public void testCustomBeanDeserializer() throws Exception } // [Issue#87]: delegating deserializer + @Test public void testDelegating() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -465,6 +472,7 @@ public Immutable convert(JsonNode value) } // [databind#623] + @Test public void testJsonNodeDelegating() throws Exception { SimpleModule module = new SimpleModule("test", Version.unknownVersion()); @@ -485,6 +493,7 @@ public Immutable convert(JsonNode root, DeserializationContext ctxt) throws IOEx assertEquals(3, imm.y); } + @Test public void testIssue882() throws Exception { Model original = new Model(Collections.singletonMap(new CustomKey(123), "test")); @@ -496,6 +505,7 @@ public void testIssue882() throws Exception } // [#337]: convenience methods for custom deserializers to use + @Test public void testContextReadValue() throws Exception { ObjectMapper mapper = new ObjectMapper(); @@ -516,6 +526,7 @@ public void testContextReadValue() throws Exception } // [#631]: "current value" access + @Test public void testCurrentValueAccess() throws Exception { Issue631Bean bean = MAPPER.readValue(a2q("{'prop':'stuff'}"), @@ -524,6 +535,7 @@ public void testCurrentValueAccess() throws Exception assertEquals("prop/Issue631Bean", bean.prop); } + @Test public void testCustomStringDeser() throws Exception { ObjectMapper mapper = new ObjectMapper().registerModule( @@ -535,6 +547,7 @@ public void testCustomStringDeser() throws Exception assertEquals("FOO", sw.str); } + @Test public void testDelegatingDeserializer() throws Exception { ObjectMapper mapper = new ObjectMapper().registerModule( @@ -544,6 +557,7 @@ public void testDelegatingDeserializer() throws Exception } // [databind#2392] + @Test public void testModifyingCustomDeserializer() throws Exception { ObjectMapper mapper = jsonMapperBuilder() @@ -565,6 +579,7 @@ public JsonDeserializer modifyDeserializer(DeserializationConfig config, } // [databind#2452] + @Test public void testCustomDeserializerWithReadTree() throws Exception { ObjectMapper mapper = jsonMapperBuilder() @@ -581,6 +596,7 @@ public void testCustomDeserializerWithReadTree() throws Exception } // [databind#3002] + @Test public void testCustomDeserializerWithReadTreeAsValue() throws Exception { final String json = a2q("{'point':{'x':13, 'y':-4}, 'name':'Foozibald' }"); @@ -603,6 +619,7 @@ public void testCustomDeserializerWithReadTreeAsValue() throws Exception } // [databind#3748] + @Test public void testBasicDelegatingDeser() throws Exception { Delegating3748 deser = new Delegating3748(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestFieldDeserialization.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestFieldDeserialization.java index e48f73b65e..a90986da53 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestFieldDeserialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestFieldDeserialization.java @@ -1,17 +1,23 @@ package com.fasterxml.jackson.databind.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.*; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*; + /** * Unit tests for verifying that field-backed properties can also be * deserialized as well as setter-accessible properties. */ public class TestFieldDeserialization - extends BaseMapTest { static class SimpleFieldBean { @@ -88,6 +94,7 @@ static class AbstractWrapper { private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testSimpleAutoDetect() throws Exception { SimpleFieldBean result = MAPPER.readValue("{ \"x\" : -13 }", @@ -96,6 +103,7 @@ public void testSimpleAutoDetect() throws Exception assertEquals(0, result.y); } + @Test public void testSimpleAnnotation() throws Exception { SimpleFieldBean2 bean = MAPPER.readValue("{ \"values\" : [ \"x\", \"y\" ] }", @@ -107,6 +115,7 @@ public void testSimpleAnnotation() throws Exception assertEquals("y", values[1]); } + @Test public void testNoAutoDetect() throws Exception { NoAutoDetectBean bean = MAPPER.readValue("{ \"z\" : 7 }", @@ -114,6 +123,7 @@ public void testNoAutoDetect() throws Exception assertEquals(7, bean._z); } + @Test public void testTypeAnnotation() throws Exception { AbstractWrapper w = MAPPER.readValue("{ \"value\" : \"abc\" }", @@ -124,6 +134,7 @@ public void testTypeAnnotation() throws Exception assertEquals("abc", ((Concrete)bean).value); } + @Test public void testResolvedDups1() throws Exception { DupFieldBean result = MAPPER.readValue(a2q("{'z':3}"), DupFieldBean.class); @@ -131,6 +142,7 @@ public void testResolvedDups1() throws Exception assertEquals(0, result.z); } + @Test public void testFailingDups2() throws Exception { // Fails because both fields have explicit annotation @@ -142,6 +154,7 @@ public void testFailingDups2() throws Exception } } + @Test public void testOkFieldOverride() throws Exception { OkDupFieldBean result = MAPPER.readValue("{ \"x\" : 1, \"y\" : 2 }", diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestFloats.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestFloats.java index 3ea903b8f3..a66f888327 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestFloats.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestFloats.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.databind.deser; -import com.fasterxml.jackson.databind.BaseMapTest; +import java.io.InputStream; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.InputStream; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; -public class TestFloats extends BaseMapTest +public class TestFloats { /* @@ -16,6 +21,7 @@ public class TestFloats extends BaseMapTest private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testFloatPrimitive() throws Exception { assertEquals(7.038531e-26f, MAPPER.readValue("\"7.038531e-26\"", float.class)); @@ -25,6 +31,7 @@ public void testFloatPrimitive() throws Exception assertEquals("1.4E-45", MAPPER.readValue("\"7.006492321624086e-46\"", float.class).toString()); } + @Test public void testFloatClass() throws Exception { assertEquals(Float.valueOf(7.038531e-26f), MAPPER.readValue("\"7.038531e-26\"", Float.class)); @@ -34,6 +41,7 @@ public void testFloatClass() throws Exception assertEquals("1.4E-45", MAPPER.readValue("\"7.006492321624086e-46\"", Float.class).toString()); } + @Test public void testArrayOfFloatPrimitives() throws Exception { StringBuilder sb = new StringBuilder(); @@ -52,6 +60,7 @@ public void testArrayOfFloatPrimitives() throws Exception } // for [jackson-core#757] + @Test public void testBigArrayOfFloatPrimitives() throws Exception { try (InputStream stream = TestFloats.class.getResourceAsStream("/data/float-array-755.txt")) { float[] floats = MAPPER.readValue(stream, float[].class); @@ -63,6 +72,7 @@ public void testBigArrayOfFloatPrimitives() throws Exception { } } + @Test public void testArrayOfFloats() throws Exception { StringBuilder sb = new StringBuilder(); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestSetterlessProperties.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestSetterlessProperties.java index 9f05f063fd..f77a34d73c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestSetterlessProperties.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestSetterlessProperties.java @@ -2,11 +2,18 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.MismatchedInputException; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.jsonMapperBuilder; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; + /** * Unit tests for verifying that feature requested * via [JACKSON-88] ("setterless collections") work as @@ -14,7 +21,6 @@ * with JAXB. */ public class TestSetterlessProperties - extends BaseMapTest { static class CollectionBean { @@ -48,6 +54,7 @@ public List getList() { /********************************************************** */ + @Test public void testSimpleSetterlessCollectionOk() throws Exception { @@ -63,6 +70,7 @@ public void testSimpleSetterlessCollectionOk() * Let's also verify that disabling the feature makes * deserialization fail for setterless bean */ + @Test public void testSimpleSetterlessCollectionFailure() throws Exception { @@ -86,6 +94,7 @@ public void testSimpleSetterlessCollectionFailure() } } + @Test public void testSimpleSetterlessMapOk() throws Exception { @@ -97,6 +106,7 @@ public void testSimpleSetterlessMapOk() assertEquals(Integer.valueOf(-3), m.get("b")); } + @Test public void testSimpleSetterlessMapFailure() throws Exception { @@ -116,6 +126,7 @@ public void testSimpleSetterlessMapFailure() /* Test precedence of "getter-as-setter" (for Lists) versus * field for same property. */ + @Test public void testSetterlessPrecedence() throws Exception { ObjectMapper m = jsonMapperBuilder() diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestValueAnnotations.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestValueAnnotations.java index 4e5c4b55d0..dcdb5eac17 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestValueAnnotations.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestValueAnnotations.java @@ -3,19 +3,25 @@ import java.io.IOException; import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import static org.junit.jupiter.api.Assertions.*; + +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; +import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; + /** * This unit test suite tests use of "value" Annotations; * annotations that define actual type (Class) to use for * deserialization. */ public class TestValueAnnotations - extends BaseMapTest { /* /********************************************************** @@ -244,6 +250,7 @@ public void setMap(Map m) private final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testOverrideClassValid() throws Exception { CollectionHolder result = MAPPER.readValue @@ -255,6 +262,7 @@ public void testOverrideClassValid() throws Exception assertEquals("test", strs.iterator().next()); } + @Test public void testOverrideMapValid() throws Exception { // note: expecting conversion from number to String, as well @@ -268,6 +276,7 @@ public void testOverrideMapValid() throws Exception assertEquals("3", value); } + @Test public void testOverrideArrayClass() throws Exception { ArrayHolder result = MAPPER.readValue @@ -279,6 +288,7 @@ public void testOverrideArrayClass() throws Exception assertEquals("test", strs[0]); } + @Test public void testOverrideClassInvalid() throws Exception { // should fail due to incompatible Annotation @@ -297,6 +307,7 @@ public void testOverrideClassInvalid() throws Exception /********************************************************** */ + @Test public void testRootInterfaceAs() throws Exception { RootInterface value = MAPPER.readValue("{\"a\":\"abc\" }", RootInterface.class); @@ -304,6 +315,7 @@ public void testRootInterfaceAs() throws Exception assertEquals("abc", value.getA()); } + @Test public void testRootInterfaceUsing() throws Exception { RootString value = MAPPER.readValue("\"xxx\"", RootString.class); @@ -311,6 +323,7 @@ public void testRootInterfaceUsing() throws Exception assertEquals("xxx", value.contents()); } + @Test public void testRootListAs() throws Exception { RootMap value = MAPPER.readValue("{\"a\":\"b\"}", RootMap.class); @@ -320,6 +333,7 @@ public void testRootListAs() throws Exception assertEquals("b", ((RootString) v2).contents()); } + @Test public void testRootMapAs() throws Exception { RootList value = MAPPER.readValue("[ \"c\" ]", RootList.class); @@ -336,6 +350,7 @@ public void testRootMapAs() throws Exception */ @SuppressWarnings("unchecked") + @Test public void testOverrideKeyClassValid() throws Exception { MapKeyHolder result = MAPPER.readValue("{ \"map\" : { \"xxx\" : \"yyy\" } }", MapKeyHolder.class); @@ -349,6 +364,7 @@ public void testOverrideKeyClassValid() throws Exception assertEquals("yyy", en.getValue()); } + @Test public void testOverrideKeyClassInvalid() throws Exception { // should fail due to incompatible Annotation @@ -368,6 +384,7 @@ public void testOverrideKeyClassInvalid() throws Exception */ @SuppressWarnings("unchecked") + @Test public void testOverrideContentClassValid() throws Exception { ListContentHolder result = MAPPER.readValue("{ \"list\" : [ \"abc\" ] }", ListContentHolder.class); @@ -378,6 +395,7 @@ public void testOverrideContentClassValid() throws Exception assertEquals("abc", ((StringWrapper) value)._string); } + @Test public void testOverrideArrayContents() throws Exception { ArrayContentHolder result = MAPPER.readValue("{ \"data\" : [ 1, 2, 3 ] }", @@ -390,6 +408,7 @@ public void testOverrideArrayContents() throws Exception assertEquals(3L, data[2]); } + @Test public void testOverrideMapContents() throws Exception { MapContentHolder result = MAPPER.readValue("{ \"map\" : { \"a\" : 9 } }", @@ -402,6 +421,7 @@ public void testOverrideMapContents() throws Exception } // [databind#2553] + @Test public void testRawListTypeContentAs() throws Exception { List2553 list = MAPPER.readValue("{\"items\": [{\"name\":\"item1\"}]}", List2553.class); diff --git a/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java b/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java index 2acac3efdd..75d24c7fa1 100644 --- a/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java +++ b/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java @@ -1,9 +1,13 @@ package com.fasterxml.jackson.databind.testutil; import java.io.IOException; +import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.*; +import com.fasterxml.jackson.annotation.JsonCreator; + +import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; @@ -22,7 +26,190 @@ */ public class DatabindTestUtil { - /* + /* + /********************************************************** + /* Some sample documents: + /********************************************************** + */ + protected static final int SAMPLE_SPEC_VALUE_WIDTH = 800; + protected static final int SAMPLE_SPEC_VALUE_HEIGHT = 600; + protected static final String SAMPLE_SPEC_VALUE_TITLE = "View from 15th Floor"; + protected static final String SAMPLE_SPEC_VALUE_TN_URL = "http://www.example.com/image/481989943"; + protected static final int SAMPLE_SPEC_VALUE_TN_HEIGHT = 125; + protected static final String SAMPLE_SPEC_VALUE_TN_WIDTH = "100"; + protected static final int SAMPLE_SPEC_VALUE_TN_ID1 = 116; + protected static final int SAMPLE_SPEC_VALUE_TN_ID2 = 943; + protected static final int SAMPLE_SPEC_VALUE_TN_ID3 = 234; + protected static final int SAMPLE_SPEC_VALUE_TN_ID4 = 38793; + + public static final String SAMPLE_DOC_JSON_SPEC = + "{\n" + +" \"Image\" : {\n" + +" \"Width\" : "+SAMPLE_SPEC_VALUE_WIDTH+",\n" + +" \"Height\" : "+SAMPLE_SPEC_VALUE_HEIGHT+"," + +"\"Title\" : \""+SAMPLE_SPEC_VALUE_TITLE+"\",\n" + +" \"Thumbnail\" : {\n" + +" \"Url\" : \""+SAMPLE_SPEC_VALUE_TN_URL+"\",\n" + +"\"Height\" : "+SAMPLE_SPEC_VALUE_TN_HEIGHT+",\n" + +" \"Width\" : \""+SAMPLE_SPEC_VALUE_TN_WIDTH+"\"\n" + +" },\n" + +" \"IDs\" : ["+SAMPLE_SPEC_VALUE_TN_ID1+","+SAMPLE_SPEC_VALUE_TN_ID2+","+SAMPLE_SPEC_VALUE_TN_ID3+","+SAMPLE_SPEC_VALUE_TN_ID4+"]\n" + +" }" + +"}" + ; + + public static void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents) + throws IOException + { + verifyJsonSpecSampleDoc(jp, verifyContents, true); + } + + public static void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents, + boolean requireNumbers) + throws IOException + { + if (!jp.hasCurrentToken()) { + jp.nextToken(); + } + assertToken(JsonToken.START_OBJECT, jp.currentToken()); // main object + + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Image' + if (verifyContents) { + verifyFieldName(jp, "Image"); + } + + assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'image' object + + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width' + if (verifyContents) { + verifyFieldName(jp, "Width"); + } + + verifyIntToken(jp.nextToken(), requireNumbers); + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_WIDTH); + } + + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height' + if (verifyContents) { + verifyFieldName(jp, "Height"); + } + + verifyIntToken(jp.nextToken(), requireNumbers); + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_HEIGHT); + } + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Title' + if (verifyContents) { + verifyFieldName(jp, "Title"); + } + assertToken(JsonToken.VALUE_STRING, jp.nextToken()); + assertEquals(SAMPLE_SPEC_VALUE_TITLE, getAndVerifyText(jp)); + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Thumbnail' + if (verifyContents) { + verifyFieldName(jp, "Thumbnail"); + } + + assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'thumbnail' object + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Url' + if (verifyContents) { + verifyFieldName(jp, "Url"); + } + assertToken(JsonToken.VALUE_STRING, jp.nextToken()); + if (verifyContents) { + assertEquals(SAMPLE_SPEC_VALUE_TN_URL, getAndVerifyText(jp)); + } + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height' + if (verifyContents) { + verifyFieldName(jp, "Height"); + } + verifyIntToken(jp.nextToken(), requireNumbers); + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_HEIGHT); + } + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width' + if (verifyContents) { + verifyFieldName(jp, "Width"); + } + // Width value is actually a String in the example + assertToken(JsonToken.VALUE_STRING, jp.nextToken()); + if (verifyContents) { + assertEquals(SAMPLE_SPEC_VALUE_TN_WIDTH, getAndVerifyText(jp)); + } + + assertToken(JsonToken.END_OBJECT, jp.nextToken()); // 'thumbnail' object + assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'IDs' + assertToken(JsonToken.START_ARRAY, jp.nextToken()); // 'ids' array + verifyIntToken(jp.nextToken(), requireNumbers); // ids[0] + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID1); + } + verifyIntToken(jp.nextToken(), requireNumbers); // ids[1] + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID2); + } + verifyIntToken(jp.nextToken(), requireNumbers); // ids[2] + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID3); + } + verifyIntToken(jp.nextToken(), requireNumbers); // ids[3] + if (verifyContents) { + verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID4); + } + assertToken(JsonToken.END_ARRAY, jp.nextToken()); // 'ids' array + + assertToken(JsonToken.END_OBJECT, jp.nextToken()); // 'image' object + + assertToken(JsonToken.END_OBJECT, jp.nextToken()); // main object + } + + private static void verifyIntToken(JsonToken t, boolean requireNumbers) + { + if (t == JsonToken.VALUE_NUMBER_INT) { + return; + } + if (requireNumbers) { // to get error + assertToken(JsonToken.VALUE_NUMBER_INT, t); + } + // if not number, must be String + if (t != JsonToken.VALUE_STRING) { + fail("Expected INT or STRING value, got "+t); + } + } + + private static void verifyFieldName(JsonParser p, String expName) + throws IOException + { + assertEquals(expName, p.getText()); + assertEquals(expName, p.currentName()); + } + + private static void verifyIntValue(JsonParser p, long expValue) + throws IOException + { + // First, via textual + assertEquals(String.valueOf(expValue), p.getText()); + } + + /* + /********************************************************** + /* Parser/generator construction + /********************************************************** + */ + + public static JsonParser createParserUsingReader(String input) + throws IOException + { + return createParserUsingReader(new JsonFactory(), input); + } + + private static JsonParser createParserUsingReader(JsonFactory f, String input) + throws IOException + { + return f.createParser(new StringReader(input)); + } + + /* /********************************************************** /* Shared helper classes /********************************************************** @@ -82,10 +269,10 @@ public Point(int x0, int y0) { @Override public boolean equals(Object o) { - if (!(o instanceof BaseMapTest.Point)) { + if (!(o instanceof Point)) { return false; } - BaseMapTest.Point other = (BaseMapTest.Point) o; + Point other = (Point) o; return (other.x == x) && (other.y == y); } @@ -95,6 +282,18 @@ public String toString() { } } + public static class ObjectWrapper { + final Object object; + protected ObjectWrapper(final Object object) { + this.object = object; + } + public Object getObject() { return object; } + @JsonCreator + static ObjectWrapper jsonValue(final Object object) { + return new ObjectWrapper(object); + } + } + /* /********************************************************** /* Factory methods @@ -219,4 +418,26 @@ public static void assertValidLocation(JsonLocation location) { assertNotNull(location, "Should have non-null location"); assertTrue(location.getLineNr() > 0, "Should have positive line number"); } + + /** + * Method that gets textual contents of the current token using + * available methods, and ensures results are consistent, before + * returning them + */ + private static String getAndVerifyText(JsonParser jp) + throws IOException + { + // Ok, let's verify other accessors + int actLen = jp.getTextLength(); + char[] ch = jp.getTextCharacters(); + String str2 = new String(ch, jp.getTextOffset(), actLen); + String str = jp.getText(); + + if (str.length() != actLen) { + fail("Internal problem (jp.token == "+jp.currentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen); + } + assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same"); + + return str; + } }