From d6f005d7edcfb1800bfbff36583d7c1427049f30 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 2 Oct 2023 20:44:51 -0700 Subject: [PATCH] test refactoring --- .../jackson/databind/ObjectMapperTest.java | 23 ++----------------- .../jsontype/ExistingPropertyTest.java | 19 +++++++++++++-- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java b/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java index bcda31b9e3..8a60355de3 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java @@ -1,14 +1,11 @@ package com.fasterxml.jackson.databind; -import com.fasterxml.jackson.databind.module.SimpleModule; import java.io.*; import java.util.*; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.json.JsonWriteFeature; @@ -17,6 +14,7 @@ import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.node.*; public class ObjectMapperTest extends BaseMapTest @@ -53,15 +51,6 @@ public void writeArrayValueSeparator(JsonGenerator g) throws IOException @SuppressWarnings("serial") static class NoCopyMapper extends ObjectMapper { } - // [databind#2785] - @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "packetType") - public interface Base2785 { - } - @JsonTypeName("myType") - static class Impl2785 implements Base2785 { - } - private final ObjectMapper MAPPER = newJsonMapper(); /* @@ -196,15 +185,7 @@ public void testCopyOfConfigOverrides() throws Exception assertSame(customVis, config2.getDefaultVisibilityChecker()); } - // [databind#2785] - public void testCopyOfSubtypeResolver2785() throws Exception { - ObjectMapper objectMapper = new ObjectMapper().copy(); - objectMapper.registerSubtypes(Impl2785.class); - Object result = objectMapper.readValue("{ \"packetType\": \"myType\" }", Base2785.class); - assertNotNull(result); - } - - public void testCopyWith() throws JsonProcessingException { + public void testCopyWith() throws Exception { ObjectMapper mapper = new ObjectMapper(); //configuring some settings to non-defaults mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/ExistingPropertyTest.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/ExistingPropertyTest.java index b2f498c463..20dc93bbda 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/ExistingPropertyTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/ExistingPropertyTest.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; import com.fasterxml.jackson.core.type.TypeReference; - import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.ObjectMapper; @@ -191,6 +190,15 @@ static class Bean1635A extends Bean1635 { static class Bean1635Default extends Bean1635 { } + // [databind#2785] + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "packetType") + public interface Base2785 { + } + @JsonTypeName("myType") + static class Impl2785 implements Base2785 { + } + // [databind#3271] @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, visible = true, property = "type", defaultImpl = DefaultShape3271.class) @@ -459,8 +467,15 @@ public void testExistingEnumTypeIdViaDefault() throws Exception assertEquals(ABC.C, result.type); } - // [databind#3271]: verify that `null` token does not become "null" String + // [databind#2785] + public void testCopyOfSubtypeResolver2785() throws Exception { + ObjectMapper objectMapper = new ObjectMapper().copy(); + objectMapper.registerSubtypes(Impl2785.class); + Object result = objectMapper.readValue("{ \"packetType\": \"myType\" }", Base2785.class); + assertNotNull(result); + } + // [databind#3271]: verify that `null` token does not become "null" String public void testDeserializationWithValidType() throws Exception { Shape3271 deserShape = MAPPER.readValue("{\"type\":\"square\"}", Shape3271.class); assertEquals("square", deserShape.getType());