From 61ef2cb6a1f365df5faf10a77aae6e1b8f4d21ae Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 10 Oct 2024 18:52:38 -0700 Subject: [PATCH] Prep work for #4659 (reduce use of TypeFactory.defaultInstance()) (#4745) --- .../databind/SerializeUsingJDKTest.java | 2 +- .../contextual/ContextualKeyTypesTest.java | 6 +-- .../deser/creators/ValueInstantiatorTest.java | 2 +- .../jdk/MapWithGenericValuesDeserTest.java | 7 +-- .../databind/exc/BasicExceptionTest.java | 5 +- .../ext/MiscJavaXMLTypesReadWriteTest.java | 2 +- .../MethodGenericTypeResolverTest.java | 5 +- .../TestGenericListSerialization.java | 2 +- .../jsontype/TestPolymorphicDeduction.java | 8 +-- .../databind/jsontype/TestTypeNames.java | 2 +- .../jsontype/TestTypedDeserialization.java | 2 +- .../deftyping/TestDefaultForMaps.java | 2 +- .../jsontype/jdk/TypedArrayDeserTest.java | 6 +-- .../databind/module/TestTypeModifiers.java | 2 +- .../databind/testutil/DatabindTestUtil.java | 7 ++- .../jackson/databind/type/JavaTypeTest.java | 31 +++++------ .../databind/type/RecursiveTypeTest.java | 7 ++- .../databind/type/TypeBindingsTest.java | 7 ++- .../databind/type/TypeFactoryTest.java | 52 +++++++++---------- .../TypeFactoryWithRecursiveTypesTest.java | 5 +- .../databind/type/TypeResolutionTest.java | 11 ++-- .../jackson/databind/util/BeanUtilTest.java | 2 +- .../jackson/databind/util/ClassUtilTest.java | 4 +- 23 files changed, 93 insertions(+), 86 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/SerializeUsingJDKTest.java b/src/test/java/com/fasterxml/jackson/databind/SerializeUsingJDKTest.java index 0ad3174095..0b1185c93c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/SerializeUsingJDKTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/SerializeUsingJDKTest.java @@ -223,7 +223,7 @@ public void testObjectMapper() throws Exception @Test public void testTypeFactory() throws Exception { - TypeFactory orig = TypeFactory.defaultInstance(); + TypeFactory orig = defaultTypeFactory(); JavaType t = orig.constructType(JavaType.class); assertNotNull(t); diff --git a/src/test/java/com/fasterxml/jackson/databind/contextual/ContextualKeyTypesTest.java b/src/test/java/com/fasterxml/jackson/databind/contextual/ContextualKeyTypesTest.java index cd606eae45..449f8d36f5 100644 --- a/src/test/java/com/fasterxml/jackson/databind/contextual/ContextualKeyTypesTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/contextual/ContextualKeyTypesTest.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.deser.ContextualKeyDeserializer; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.ContextualSerializer; -import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -20,7 +20,7 @@ * Tests to ensure that we can do contextual key serializers and * deserializers as well as value ser/deser. */ -public class ContextualKeyTypesTest +public class ContextualKeyTypesTest extends DatabindTestUtil { /* /********************************************************** @@ -99,7 +99,7 @@ public void testSimpleKeySer() throws Exception mapper.registerModule(module); Map input = new HashMap(); input.put("a", Integer.valueOf(3)); - String json = mapper.writerFor(TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class)) + String json = mapper.writerFor(defaultTypeFactory().constructMapType(HashMap.class, String.class, Object.class)) .writeValueAsString(input); assertEquals("{\"prefix:a\":3}", json); } diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/ValueInstantiatorTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/ValueInstantiatorTest.java index 8e270036c2..0732c2d38e 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/ValueInstantiatorTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/ValueInstantiatorTest.java @@ -251,7 +251,7 @@ static class MyDelegateMapInstantiator extends ValueInstantiator.Base @Override public JavaType getDelegateType(DeserializationConfig config) { - return TypeFactory.defaultInstance().constructType(Object.class); + return defaultTypeFactory().constructType(Object.class); } @Override diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapWithGenericValuesDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapWithGenericValuesDeserTest.java index b1001804b2..e1c1839c95 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapWithGenericValuesDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapWithGenericValuesDeserTest.java @@ -8,13 +8,14 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import com.fasterxml.jackson.databind.type.TypeFactory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @SuppressWarnings("serial") -public class MapWithGenericValuesDeserTest +public class MapWithGenericValuesDeserTest extends DatabindTestUtil { /* /********************************************************** @@ -154,7 +155,7 @@ public void testKeyViaCtor() throws Exception { ObjectMapper mapper = new ObjectMapper(); Map map = mapper.readValue("{\"a\":123}", - TypeFactory.defaultInstance().constructMapType(HashMap.class, KeyTypeCtor.class, Integer.class)); + defaultTypeFactory().constructMapType(HashMap.class, KeyTypeCtor.class, Integer.class)); assertEquals(1, map.size()); Map.Entry entry = map.entrySet().iterator().next(); assertEquals(Integer.valueOf(123), entry.getValue()); @@ -168,7 +169,7 @@ public void testKeyViaFactory() throws Exception { ObjectMapper mapper = new ObjectMapper(); Map map = mapper.readValue("{\"a\":123}", - TypeFactory.defaultInstance().constructMapType(HashMap.class, KeyTypeFactory.class, Integer.class)); + defaultTypeFactory().constructMapType(HashMap.class, KeyTypeFactory.class, Integer.class)); assertEquals(1, map.size()); Map.Entry entry = map.entrySet().iterator().next(); assertEquals(Integer.valueOf(123), entry.getValue()); diff --git a/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java b/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java index d018590dbf..6264290cf4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java @@ -10,13 +10,14 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import com.fasterxml.jackson.databind.type.TypeFactory; import static org.junit.jupiter.api.Assertions.*; import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; -public class BasicExceptionTest +public class BasicExceptionTest extends DatabindTestUtil { static class User { public String user; @@ -32,7 +33,7 @@ static class Users { @Test public void testBadDefinition() throws Exception { - JavaType t = TypeFactory.defaultInstance().constructType(String.class); + JavaType t = defaultTypeFactory().constructType(String.class); JsonParser p = JSON_F.createParser("[]"); InvalidDefinitionException e = new InvalidDefinitionException(p, "Testing", t); diff --git a/src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java b/src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java index 118c14edff..130cd38ca2 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java @@ -102,7 +102,7 @@ private String removeZ(String dateStr) { public void testDeserializerLoading() { CoreXMLDeserializers sers = new CoreXMLDeserializers(); - TypeFactory f = TypeFactory.defaultInstance(); + TypeFactory f = defaultTypeFactory(); sers.findBeanDeserializer(f.constructType(Duration.class), null, null); sers.findBeanDeserializer(f.constructType(XMLGregorianCalendar.class), null, null); sers.findBeanDeserializer(f.constructType(QName.class), null, null); diff --git a/src/test/java/com/fasterxml/jackson/databind/introspect/MethodGenericTypeResolverTest.java b/src/test/java/com/fasterxml/jackson/databind/introspect/MethodGenericTypeResolverTest.java index 951910e398..b5008a878e 100644 --- a/src/test/java/com/fasterxml/jackson/databind/introspect/MethodGenericTypeResolverTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/introspect/MethodGenericTypeResolverTest.java @@ -5,11 +5,12 @@ import java.util.concurrent.atomic.AtomicReference; import com.fasterxml.jackson.annotation.JsonCreator; + import com.fasterxml.jackson.core.type.TypeReference; + import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import com.fasterxml.jackson.databind.type.TypeBindings; -import com.fasterxml.jackson.databind.type.TypeFactory; import org.junit.jupiter.api.Test; @@ -18,7 +19,7 @@ public class MethodGenericTypeResolverTest extends DatabindTestUtil { private static final TypeResolutionContext EMPTY_CONTEXT = - new TypeResolutionContext.Empty(TypeFactory.defaultInstance()); + new TypeResolutionContext.Empty(defaultTypeFactory()); public static AtomicReference simple(T input) { throw new UnsupportedOperationException(); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestGenericListSerialization.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestGenericListSerialization.java index 4c47c1aff4..48e0206a68 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestGenericListSerialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestGenericListSerialization.java @@ -64,7 +64,7 @@ public void testSubTypesFor356() throws Exception .configure(MapperFeature.USE_STATIC_TYPING, true) .build(); - JavaType rootType = TypeFactory.defaultInstance().constructType(new TypeReference>>() { }); + JavaType rootType = defaultTypeFactory().constructType(new TypeReference>>() { }); byte[] json = mapper.writerFor(rootType).writeValueAsBytes(input); JSONResponse> out = mapper.readValue(json, 0, json.length, rootType); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicDeduction.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicDeduction.java index e29020d781..e746671c47 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicDeduction.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicDeduction.java @@ -185,7 +185,7 @@ public void testContainedInferenceOfEmptySubtype() throws Exception { @Test public void testListInference() throws Exception { - JavaType listOfCats = TypeFactory.defaultInstance().constructParametricType(List.class, Cat.class); + JavaType listOfCats = defaultTypeFactory().constructParametricType(List.class, Cat.class); List boxes = MAPPER.readValue(arrayOfCatsJson, listOfCats); assertTrue(boxes.get(0) instanceof LiveCat); assertTrue(boxes.get(1) instanceof DeadCat); @@ -193,7 +193,7 @@ public void testListInference() throws Exception { @Test public void testMapInference() throws Exception { - JavaType mapOfCats = TypeFactory.defaultInstance().constructParametricType(Map.class, String.class, Cat.class); + JavaType mapOfCats = defaultTypeFactory().constructParametricType(Map.class, String.class, Cat.class); Map map = MAPPER.readValue(mapOfCatsJson, mapOfCats); assertEquals(1, map.size()); assertTrue(map.entrySet().iterator().next().getValue() instanceof LiveCat); @@ -281,7 +281,7 @@ public void testDefaultImpl() throws Exception { @Test public void testSimpleSerialization() throws Exception { // Given: - JavaType listOfCats = TypeFactory.defaultInstance().constructParametricType(List.class, Cat.class); + JavaType listOfCats = defaultTypeFactory().constructParametricType(List.class, Cat.class); List list = MAPPER.readValue(arrayOfCatsJson, listOfCats); Cat cat = list.get(0); // When: @@ -293,7 +293,7 @@ public void testSimpleSerialization() throws Exception { @Test public void testListSerialization() throws Exception { // Given: - JavaType listOfCats = TypeFactory.defaultInstance().constructParametricType(List.class, Cat.class); + JavaType listOfCats = defaultTypeFactory().constructParametricType(List.class, Cat.class); List list = MAPPER.readValue(arrayOfCatsJson, listOfCats); // When: String json = MAPPER.writeValueAsString(list); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java index ea04d62ca4..05a42e157a 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java @@ -91,7 +91,7 @@ public void testRoundTrip() throws Exception }; String json = MAPPER.writeValueAsString(input); List output = MAPPER.readValue(json, - TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, Animal.class)); + defaultTypeFactory().constructCollectionType(ArrayList.class, Animal.class)); assertEquals(input.length, output.size()); for (int i = 0, len = input.length; i < len; ++i) { assertEquals(input[i], output.get(i), "Entry #"+i+" differs, input = '"+json+"'"); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypedDeserialization.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypedDeserialization.java index 744df051fb..2a8f5590d9 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypedDeserialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypedDeserialization.java @@ -220,7 +220,7 @@ public void testListAsArray() throws Exception +asJSONObjectValueString(m, "@classy", Fish.class.getName()) +", null\n]"; - JavaType expType = TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, Animal.class); + JavaType expType = defaultTypeFactory().constructCollectionType(ArrayList.class, Animal.class); List animals = m.readValue(JSON, expType); assertNotNull(animals); assertEquals(4, animals.size()); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForMaps.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForMaps.java index 1a81827150..c64cf1ae47 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForMaps.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForMaps.java @@ -125,7 +125,7 @@ protected TypeNameIdResolver createTypeNameIdResolver(boolean forSerialization) subtypes.add(new NamedType(HashMap.class, "HMap")); ObjectMapper mapper = new ObjectMapper(); return TypeNameIdResolver.construct(mapper.getDeserializationConfig(), - TypeFactory.defaultInstance().constructType(Object.class), subtypes, forSerialization, !forSerialization); + defaultTypeFactory().constructType(Object.class), subtypes, forSerialization, !forSerialization); } @Test diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/jdk/TypedArrayDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/jdk/TypedArrayDeserTest.java index bbe86a23e9..cb2a30407b 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/jdk/TypedArrayDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/jdk/TypedArrayDeserTest.java @@ -56,7 +56,7 @@ public void testIntList() throws Exception ObjectMapper m = new ObjectMapper(); // uses WRAPPER_OBJECT inclusion String JSON = "{\""+TypedListAsWrapper.class.getName()+"\":[4,5, 6]}"; - JavaType type = TypeFactory.defaultInstance().constructCollectionType(TypedListAsWrapper.class, Integer.class); + JavaType type = defaultTypeFactory().constructCollectionType(TypedListAsWrapper.class, Integer.class); TypedListAsWrapper result = m.readValue(JSON, type); assertNotNull(result); assertEquals(3, result.size()); @@ -76,7 +76,7 @@ public void testBooleanListAsProp() throws Exception ObjectMapper m = new ObjectMapper(); // tries to use PROPERTY inclusion; but for ARRAYS (and scalars) will become ARRAY_WRAPPER String JSON = "[\""+TypedListAsProp.class.getName()+"\",[true, false]]"; - JavaType type = TypeFactory.defaultInstance().constructCollectionType(TypedListAsProp.class, Boolean.class); + JavaType type = defaultTypeFactory().constructCollectionType(TypedListAsProp.class, Boolean.class); TypedListAsProp result = m.readValue(JSON, type); assertNotNull(result); assertEquals(2, result.size()); @@ -91,7 +91,7 @@ public void testLongListAsWrapper() throws Exception // uses OBJECT_ARRAY, works just fine String JSON = "{\""+TypedListAsWrapper.class.getName()+"\":[1, 3]}"; - JavaType type = TypeFactory.defaultInstance().constructCollectionType(TypedListAsWrapper.class, Long.class); + JavaType type = defaultTypeFactory().constructCollectionType(TypedListAsWrapper.class, Long.class); TypedListAsWrapper result = m.readValue(JSON, type); assertNotNull(result); assertEquals(2, result.size()); diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java b/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java index 65fa0c7749..5ad90148af 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java @@ -216,7 +216,7 @@ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, T */ private final ObjectMapper MAPPER_WITH_MODIFIER = JsonMapper.builder() - .typeFactory(TypeFactory.defaultInstance().withModifier(new MyTypeModifier())) + .typeFactory(defaultTypeFactory().withModifier(new MyTypeModifier())) .build(); /** 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 cf4fc1d40f..002abe14da 100644 --- a/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java +++ b/src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java @@ -367,7 +367,7 @@ protected static ObjectReader objectReader() { public static TypeFactory newTypeFactory() { // this is a work-around; no null modifier added - return TypeFactory.defaultInstance().withModifier(null); + return defaultTypeFactory().withModifier(null); } /* @@ -560,6 +560,11 @@ public static TimeZone getUTCTimeZone() { return TimeZone.getTimeZone("GMT"); } + // Separated out since "default" TypeFactory instance handling differs + // between 2.x and 3.x + public static TypeFactory defaultTypeFactory() { + return TypeFactory.defaultInstance(); + } protected JsonParser createParserUsingReader(String input) throws IOException diff --git a/src/test/java/com/fasterxml/jackson/databind/type/JavaTypeTest.java b/src/test/java/com/fasterxml/jackson/databind/type/JavaTypeTest.java index e53a97f99e..e6342ac420 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/JavaTypeTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/JavaTypeTest.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.*; @@ -19,7 +20,7 @@ * Simple tests to verify that {@link JavaType} types work to * some degree */ -public class JavaTypeTest +public class JavaTypeTest extends DatabindTestUtil { static class BaseType { } @@ -74,7 +75,7 @@ static interface StringIterator extends Iterator { } @Test public void testLocalType728() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); Method m = Issue728.class.getMethod("method", CharSequence.class); assertNotNull(m); @@ -96,7 +97,7 @@ public void testLocalType728() throws Exception @Test public void testSimpleClass() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType baseType = tf.constructType(BaseType.class); assertSame(BaseType.class, baseType.getRawClass()); assertTrue(baseType.hasRawClass(BaseType.class)); @@ -123,7 +124,7 @@ public void testSimpleClass() @Test public void testDeprecated() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType baseType = tf.constructType(BaseType.class); assertTrue(baseType.hasRawClass(BaseType.class)); assertNull(baseType.getParameterSource()); @@ -136,7 +137,7 @@ public void testDeprecated() @Test public void testArrayType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType arrayT = ArrayType.construct(tf.constructType(String.class), null); assertNotNull(arrayT); assertTrue(arrayT.isContainerType()); @@ -160,7 +161,7 @@ public void testArrayType() @Test public void testMapType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType mapT = tf.constructType(HashMap.class); assertTrue(mapT.isContainerType()); assertFalse(mapT.isIterationType()); @@ -183,7 +184,7 @@ public void testMapType() @Test public void testEnumType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType enumT = tf.constructType(MyEnum.class); // JDK actually works fine with "basic" Enum types... assertTrue(enumT.getRawClass().isEnum()); @@ -233,7 +234,7 @@ public void testClassKey() @Test public void testJavaTypeAsJLRType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t1 = tf.constructType(getClass()); // should just get it back as-is: JavaType t2 = tf.constructType(t1); @@ -244,7 +245,7 @@ public void testJavaTypeAsJLRType() @Test public void testGenericSignature1194() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); Method m; JavaType t; @@ -267,7 +268,7 @@ public void testGenericSignature1194() throws Exception @Test public void testAnchorTypeForRefTypes() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(AtomicStringReference.class); assertTrue(t.isReferenceType()); assertTrue(t.hasContentType()); @@ -283,7 +284,7 @@ public void testAnchorTypeForRefTypes() throws Exception @Test public void testObjectToReferenceSpecialization() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType base = tf.constructType(Object.class); assertTrue(base.isJavaLangObject()); @@ -296,7 +297,7 @@ public void testObjectToReferenceSpecialization() throws Exception @Test public void testConstructReferenceType() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); // do AtomicReference final JavaType refdType = tf.constructType(Long.class); JavaType t = tf.constructReferenceType(AtomicReference.class, refdType); @@ -317,7 +318,7 @@ public void testConstructReferenceType() throws Exception @Test public void testIterationTypesDirect() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); // First, type-erased types _verifyIteratorType(tf.constructType(Iterator.class), @@ -347,7 +348,7 @@ public void testIterationTypesDirect() throws Exception @Test public void testIterationTypesFromValues() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); List strings = Arrays.asList("foo", "bar"); // We will get type-erased, alas, so: Iterator stringIT = strings.iterator(); @@ -362,7 +363,7 @@ public void testIterationTypesFromValues() throws Exception @Test public void testIterationSubTypes() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); _verifyIteratorType(tf.constructType(StringIterator.class), StringIterator.class, String.class); _verifyIteratorType(tf.constructType(StringStream.class), diff --git a/src/test/java/com/fasterxml/jackson/databind/type/RecursiveTypeTest.java b/src/test/java/com/fasterxml/jackson/databind/type/RecursiveTypeTest.java index 603f756298..7679a7da2f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/RecursiveTypeTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/RecursiveTypeTest.java @@ -5,12 +5,11 @@ import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.*; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; - -public class RecursiveTypeTest +public class RecursiveTypeTest extends DatabindTestUtil { // for [databind#1301] @SuppressWarnings("serial") @@ -61,7 +60,7 @@ static ImmutablePair of(final L left, final R right) { @Test public void testRecursiveType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructType(HashTree.class); assertNotNull(type); } diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TypeBindingsTest.java b/src/test/java/com/fasterxml/jackson/databind/type/TypeBindingsTest.java index 7ae39b11fb..9c8f496075 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TypeBindingsTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TypeBindingsTest.java @@ -5,17 +5,16 @@ import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.*; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; - /** * Simple tests to verify for generic type binding functionality * implemented by {@link TypeBindings} class. */ -public class TypeBindingsTest +public class TypeBindingsTest extends DatabindTestUtil { static class AbstractType { } @@ -45,7 +44,7 @@ static class HashTree extends HashMap> { } /********************************************************** */ - private final TypeFactory DEFAULT_TF = TypeFactory.defaultInstance(); + private final TypeFactory DEFAULT_TF = defaultTypeFactory(); @Test public void testInnerType() throws Exception diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryTest.java b/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryTest.java index f63a214ada..433cca6d80 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryTest.java @@ -8,19 +8,17 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.*; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newTypeFactory; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; - /** * Simple tests to verify that the {@link TypeFactory} constructs * type information as expected. */ -public class TypeFactoryTest +public class TypeFactoryTest extends DatabindTestUtil { /* /********************************************************** @@ -108,7 +106,7 @@ public void testSimpleTypes() Date.class, }; - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); for (Class clz : classes) { assertSame(clz, tf.constructType(clz).getRawClass()); assertSame(clz, tf.constructType(clz).getRawClass()); @@ -127,7 +125,7 @@ public void testArrays() Calendar[].class, }; - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); for (Class clz : classes) { assertSame(clz, tf.constructType(clz).getRawClass()); Class elemType = clz.getComponentType(); @@ -139,7 +137,7 @@ public void testArrays() @Test public void testProperties() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(Properties.class); assertEquals(MapType.class, t.getClass()); assertSame(Properties.class, t.getRawClass()); @@ -173,7 +171,7 @@ public void testIterator() @Test public void testParametricTypes() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); // first, simple class based final JavaType t = tf.constructParametrizedType(ArrayList.class, Collection.class, String.class); // ArrayList assertEquals(CollectionType.class, t.getClass()); @@ -221,7 +219,7 @@ public void testParametricTypes() @Test public void testInvalidParametricTypes() { - final TypeFactory tf = TypeFactory.defaultInstance(); + final TypeFactory tf = defaultTypeFactory(); final JavaType strC = tf.constructType(String.class); // ensure that we can't create invalid combinations @@ -246,7 +244,7 @@ public void testInvalidParametricTypes() @Test public void testCanonicalNames() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(java.util.Calendar.class); String can = t.toCanonical(); assertEquals("java.util.Calendar", can); @@ -299,7 +297,7 @@ public void testCanonicalNames() @Test public void testCanonicalWithSpaces() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); Object objects = new TreeMap() { }; // to get subtype String reflectTypeName = objects.getClass().getGenericSuperclass().toString(); JavaType t1 = tf.constructType(objects.getClass().getGenericSuperclass()); @@ -313,7 +311,7 @@ public void testCanonicalWithSpaces() @Test public void testMalicousCanonical() { - final TypeFactory tf = TypeFactory.defaultInstance(); + final TypeFactory tf = defaultTypeFactory(); // First: too deep nesting final int NESTING = TypeParser.MAX_TYPE_NESTING + 100; @@ -354,7 +352,7 @@ public void testMalicousCanonical() public void testCollections() { // Ok, first: let's test what happens when we pass 'raw' Collection: - final TypeFactory tf = TypeFactory.defaultInstance(); + final TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(ArrayList.class); assertEquals(CollectionType.class, t.getClass()); assertSame(ArrayList.class, t.getRawClass()); @@ -388,7 +386,7 @@ public void testCollections() @Test public void testCollectionsWithBindings() { - final TypeFactory tf = TypeFactory.defaultInstance(); + final TypeFactory tf = defaultTypeFactory(); TypeBindings tb = TypeBindings.create(Set.class, new JavaType[] { tf.constructType(String.class) }); JavaType t = tf.constructType(ArrayList.class, tb); @@ -560,7 +558,7 @@ public void testTypeGeneralization() @Test public void testMapTypesRaw() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructType(HashMap.class); assertEquals(MapType.class, type.getClass()); MapType mapType = (MapType) type; @@ -571,7 +569,7 @@ public void testMapTypesRaw() @Test public void testMapTypesAdvanced() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructType(MyMap.class); assertEquals(MapType.class, type.getClass()); MapType mapType = (MapType) type; @@ -597,7 +595,7 @@ public void testMapTypesAdvanced() @Test public void testMapTypesSneaky() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructType(IntLongMap.class); assertEquals(MapType.class, type.getClass()); MapType mapType = (MapType) type; @@ -611,7 +609,7 @@ public void testMapTypesSneaky() @Test public void testSneakyFieldTypes() throws Exception { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); Field field = SneakyBean.class.getDeclaredField("intMap"); JavaType type = tf.constructType(field.getGenericType()); assertEquals(MapType.class, type.getClass()); @@ -664,7 +662,7 @@ public void testSneakySelfRefs() throws Exception @Test public void testAtomicArrayRefParameters() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructType(new TypeReference>() { }); JavaType[] params = tf.findTypeParameters(type, AtomicReference.class); assertNotNull(params); @@ -677,7 +675,7 @@ static abstract class StringIntMapEntry implements Map.Entry { } @Test public void testMapEntryResolution() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(StringIntMapEntry.class); JavaType mapEntryType = t.findSuperType(Map.Entry.class); assertNotNull(mapEntryType); @@ -696,7 +694,7 @@ public void testMapEntryResolution() @Test public void testRawCollections() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructRawCollectionType(ArrayList.class); assertTrue(type.isContainerType()); assertEquals(TypeFactory.unknownType(), type.getContentType()); @@ -713,7 +711,7 @@ public void testRawCollections() @Test public void testRawMaps() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType type = tf.constructRawMapType(HashMap.class); assertTrue(type.isContainerType()); assertEquals(TypeFactory.unknownType(), type.getKeyType()); @@ -740,7 +738,7 @@ public void testRawMaps() @Test public void testMoreSpecificType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t1 = tf.constructCollectionType(Collection.class, Object.class); JavaType t2 = tf.constructCollectionType(List.class, Object.class); @@ -763,7 +761,7 @@ public void testMoreSpecificType() @Test public void testCacheClearing() { - TypeFactory tf = TypeFactory.defaultInstance().withModifier(null); + TypeFactory tf = defaultTypeFactory().withModifier(null); assertEquals(0, tf._typeCache.size()); tf.constructType(getClass()); // 19-Oct-2015, tatu: This is pretty fragile but @@ -776,7 +774,7 @@ public void testCacheClearing() @Test public void testRawMapType() { - TypeFactory tf = TypeFactory.defaultInstance().withModifier(null); // to get a new copy + TypeFactory tf = defaultTypeFactory().withModifier(null); // to get a new copy JavaType type = tf.constructParametricType(Wrapper1297.class, Map.class); assertNotNull(type); @@ -786,7 +784,7 @@ public void testRawMapType() // for [databind#3443] @Test public void testParameterizedClassType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(new TypeReference>() { }); @@ -798,7 +796,7 @@ public void testParameterizedClassType() { // for [databind#3876] @Test public void testParameterizedSimpleType() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType charSequenceClass = tf.constructType(new TypeReference>() { }); JavaType numberClass = tf.constructType(new TypeReference>() { }); diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryWithRecursiveTypesTest.java b/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryWithRecursiveTypesTest.java index 24ff48a16d..a99baf7dec 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryWithRecursiveTypesTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TypeFactoryWithRecursiveTypesTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,7 +14,7 @@ // https://github.com/FasterXML/jackson-databind/issues/1647 -public class TypeFactoryWithRecursiveTypesTest +public class TypeFactoryWithRecursiveTypesTest extends DatabindTestUtil { static interface IFace { } @@ -29,7 +30,7 @@ static class Sub extends Base { @Test public void testBasePropertiesIncludedWhenSerializingSubWhenSubTypeLoadedAfterBaseType() throws IOException { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); tf.constructType(Base.class); tf.constructType(Sub.class); Sub sub = new Sub(); diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TypeResolutionTest.java b/src/test/java/com/fasterxml/jackson/databind/type/TypeResolutionTest.java index c437a819af..9e622909ef 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TypeResolutionTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TypeResolutionTest.java @@ -7,12 +7,13 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; @SuppressWarnings("serial") -public class TypeResolutionTest +public class TypeResolutionTest extends DatabindTestUtil { public static class LongValuedMap extends HashMap { } @@ -41,7 +42,7 @@ static class DoubleRange extends Range { @Test public void testMaps() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(new TypeReference>() { }); MapType type = (MapType) t; assertSame(LongValuedMap.class, type.getRawClass()); @@ -52,7 +53,7 @@ public void testMaps() @Test public void testListViaTypeRef() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(new TypeReference>() {}); CollectionType type = (CollectionType) t; assertSame(MyLongList.class, type.getRawClass()); @@ -62,7 +63,7 @@ public void testListViaTypeRef() @Test public void testListViaClass() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); JavaType t = tf.constructType(LongList.class); JavaType type = (CollectionType) t; assertSame(LongList.class, type.getRawClass()); @@ -72,7 +73,7 @@ public void testListViaClass() @Test public void testGeneric() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); // First, via simple sub-class JavaType t = tf.constructType(DoubleRange.class); diff --git a/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java b/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java index c73bd93952..929ea927f4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java @@ -18,7 +18,7 @@ public class BeanUtilTest extends DatabindTestUtil @Test public void testGetDefaultValue() { - TypeFactory tf = TypeFactory.defaultInstance(); + TypeFactory tf = defaultTypeFactory(); // For collection/array/Map types, should give `NOT_EMPTY`: assertEquals(JsonInclude.Include.NON_EMPTY, BeanUtil.getDefaultValue(tf.constructType(Map.class))); diff --git a/src/test/java/com/fasterxml/jackson/databind/util/ClassUtilTest.java b/src/test/java/com/fasterxml/jackson/databind/util/ClassUtilTest.java index 6181c5ae4a..051e90e5c7 100644 --- a/src/test/java/com/fasterxml/jackson/databind/util/ClassUtilTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/util/ClassUtilTest.java @@ -243,7 +243,7 @@ public void testDescs() final String stringExp = "`java.lang.String`"; assertEquals(stringExp, ClassUtil.getClassDescription("foo")); assertEquals(stringExp, ClassUtil.getClassDescription(String.class)); - final JavaType stringType = TypeFactory.defaultInstance().constructType(String.class); + final JavaType stringType = defaultTypeFactory().constructType(String.class); assertEquals(stringExp, ClassUtil.getTypeDescription(stringType)); final JavaType mapType = TypeFactory.defaultInstance().constructType( new TypeReference>() { }); @@ -254,7 +254,7 @@ public void testDescs() @Test public void testSubtypes() { - final JavaType stringType = TypeFactory.defaultInstance().constructType(String.class); + final JavaType stringType = defaultTypeFactory().constructType(String.class); List supers = ClassUtil.findSuperTypes(stringType, Object.class, false); assertEquals(Collections.emptyList(), supers);