Skip to content

Commit

Permalink
Minor test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 18, 2024
1 parent 5ef809c commit ba4cf06
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import java.math.BigInteger;
import java.util.*;

import com.fasterxml.jackson.annotation.*;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.util.TokenBuffer;

import static org.junit.jupiter.api.Assertions.*;

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.q;
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException;

/**
* Unit tests for verifying that it is possible to annotate
* various kinds of things with {@link JsonCreator} annotation.
*/
public class TestCreators
extends DatabindTestUtil
{
/*
/**********************************************************
Expand Down Expand Up @@ -109,7 +109,7 @@ static FactoryBean createIt(@JsonProperty("mixed") double xyz) {
}

/**
* Simple demonstration of INVALID construtor annotation (only
* Simple demonstration of INVALID constructor annotation (only
* defining name for first arg)
*/
static class BrokenBean {
Expand All @@ -119,33 +119,33 @@ static class BrokenBean {
}

/**
* Bean that defines both creator and factory methor as
* Bean that defines both creator and factory method as
* creators. Constructors have priority; but it is possible
* to hide it using mix-in annotations.
*/
static class CreatorBean
static class CreatorBeanWithBoth
{
String a;
int x;

@JsonCreator
protected CreatorBean(@JsonProperty("a") String paramA,
@JsonProperty("x") int paramX)
protected CreatorBeanWithBoth(@JsonProperty("a") String paramA,
@JsonProperty("x") int paramX)
{
a = "ctor:"+paramA;
x = 1+paramX;
}

private CreatorBean(String a, int x, boolean dummy) {
private CreatorBeanWithBoth(String a, int x, boolean dummy) {
this.a = a;
this.x = x;
}

@JsonCreator
public static CreatorBean buildMeUpButterCup(@JsonProperty("a") String paramA,
@JsonProperty("x") int paramX)
public static CreatorBeanWithBoth bobTheBuilder(@JsonProperty("a") String paramA,
@JsonProperty("x") int paramX)
{
return new CreatorBean("factory:"+paramA, paramX-1, false);
return new CreatorBeanWithBoth("factory:"+paramA, paramX-1, false);
}
}

Expand Down Expand Up @@ -324,7 +324,7 @@ static MapWithFactory createIt(@JsonProperty("b") Boolean b)
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testSimpleConstructor() throws Exception
Expand Down Expand Up @@ -420,10 +420,10 @@ public void testStringFactoryAlt() throws Exception
}

@Test
public void testConstructorCreator() throws Exception
public void testConstructorAndFactoryCreator() throws Exception
{
CreatorBean bean = MAPPER.readValue
("{ \"a\" : \"xyz\", \"x\" : 12 }", CreatorBean.class);
CreatorBeanWithBoth bean = MAPPER.readValue
("{ \"a\" : \"xyz\", \"x\" : 12 }", CreatorBeanWithBoth.class);
assertEquals(13, bean.x);
assertEquals("ctor:xyz", bean.a);
}
Expand Down Expand Up @@ -506,10 +506,11 @@ public void testDeferredFactoryAndProps() throws Exception
@Test
public void testFactoryCreatorWithMixin() throws Exception
{
ObjectMapper m = new ObjectMapper();
m.addMixIn(CreatorBean.class, MixIn.class);
CreatorBean bean = m.readValue
("{ \"a\" : \"xyz\", \"x\" : 12 }", CreatorBean.class);
ObjectMapper m = jsonMapperBuilder()
.addMixIn(CreatorBeanWithBoth.class, MixIn.class)
.build();
CreatorBeanWithBoth bean = m.readValue
("{ \"a\" : \"xyz\", \"x\" : 12 }", CreatorBeanWithBoth.class);
assertEquals(11, bean.x);
assertEquals("factory:xyz", bean.a);
}
Expand Down

0 comments on commit ba4cf06

Please sign in to comment.