Skip to content

Commit 3eb6534

Browse files
committed
Yet more test fixes
1 parent f262f71 commit 3eb6534

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/creators/BigCreatorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public Biggie(
5050
}
5151
}
5252

53-
private final ObjectReader BIGGIE_READER = sharedMapper().readerFor(Biggie.class);
53+
private final ObjectReader BIGGIE_READER = sharedMapper()
54+
.readerFor(Biggie.class)
55+
.without(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
5456

5557
@Test
5658
public void testBigPartial() throws Exception

src/test/java/com/fasterxml/jackson/databind/deser/creators/FailOnNullCreatorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1010

1111
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
1213
import static org.junit.jupiter.api.Assertions.fail;
1314

1415
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;
@@ -25,7 +26,7 @@ static class Person {
2526

2627
@JsonCreator
2728
public Person(@JsonProperty(value="name") String name,
28-
@JsonProperty(value="age") int age)
29+
@JsonProperty(value="age") Integer age)
2930
{
3031
this.name = name;
3132
this.age = age;
@@ -41,13 +42,13 @@ public void testRequiredNonNullParam() throws Exception
4142
// First: fine if feature is not enabled
4243
p = POINT_READER.readValue(a2q("{}"));
4344
assertEquals(null, p.name);
44-
assertEquals(Integer.valueOf(0), p.age);
45+
assertNull(p.age);
4546

4647
// Second: fine if feature is enabled but default value is not null
4748
ObjectReader r = POINT_READER.with(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES);
4849
p = POINT_READER.readValue(a2q("{'name':'John', 'age': null}"));
4950
assertEquals("John", p.name);
50-
assertEquals(Integer.valueOf(0), p.age);
51+
assertNull(p.age);
5152

5253
// Third: throws exception if property is missing
5354
try {

src/test/java/com/fasterxml/jackson/databind/deser/creators/RequiredCreatorTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
99

1010
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNull;
1112
import static org.junit.jupiter.api.Assertions.fail;
1213

1314
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;
1415

1516
public class RequiredCreatorTest
1617
{
1718
static class FascistPoint {
18-
int x, y;
19+
Integer x, y;
1920

2021
@JsonCreator
21-
public FascistPoint(@JsonProperty(value="x", required=true) int x,
22-
@JsonProperty(value="y", required=false) int y)
22+
public FascistPoint(@JsonProperty(value="x", required=true) Integer x,
23+
@JsonProperty(value="y", required=false) Integer y)
2324
{
2425
this.x = x;
2526
this.y = y;
@@ -81,7 +82,7 @@ public void testRequiredAnnotatedParam() throws Exception
8182
// also fine if 'y' is MIA
8283
p = POINT_READER.readValue(a2q("{'x':3}"));
8384
assertEquals(3, p.x);
84-
assertEquals(0, p.y);
85+
assertNull(p.y);
8586

8687
// but not so good if 'x' missing
8788
try {
@@ -100,7 +101,7 @@ public void testRequiredGloballyParam() throws Exception
100101
// as per above, ok to miss 'y' with default settings:
101102
p = POINT_READER.readValue(a2q("{'x':2}"));
102103
assertEquals(2, p.x);
103-
assertEquals(0, p.y);
104+
assertNull(p.y);
104105

105106
// but not if global checks desired
106107
ObjectReader r = POINT_READER.with(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);

src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators2.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
1616
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1717
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
18+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
1819

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

21-
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.q;
22-
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException;
23-
2422
public class TestCreators2
23+
extends DatabindTestUtil
2524
{
2625
static class HashTest
2726
{
@@ -259,7 +258,10 @@ public void testSimpleConstructor() throws Exception
259258
@Test
260259
public void testMissingPrimitives() throws Exception
261260
{
262-
Primitives p = MAPPER.readValue("{}", Primitives.class);
261+
Primitives p = MAPPER
262+
.readerFor(Primitives.class)
263+
.without(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
264+
.readValue("{}");
263265
assertFalse(p.b);
264266
assertEquals(0, p.x);
265267
assertEquals(0.0, p.d);

0 commit comments

Comments
 (0)