Skip to content

Commit

Permalink
test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 3, 2023
1 parent 44091d2 commit d6f005d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
23 changes: 2 additions & 21 deletions src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();

/*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit d6f005d

Please sign in to comment.