Skip to content

Commit 03458e9

Browse files
committed
Minor clean up of new test wrt #4453
1 parent 884af2e commit 03458e9

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiatorTest.java

+23-29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.fasterxml.jackson.databind.ObjectMapper;
99
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
10+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
1011

1112
import static org.junit.jupiter.api.Assertions.assertEquals;
1213
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -15,8 +16,19 @@
1516

1617
// [databind#2978]
1718
public class StdValueInstantiatorTest
19+
extends DatabindTestUtil
1820
{
21+
private final ObjectMapper MAPPER = newJsonMapper();
22+
1923
private static final long LONG_TEST_VALUE = 12345678901L;
24+
25+
static class Stuff {
26+
final double value;
27+
28+
Stuff(double value) {
29+
this.value = value;
30+
}
31+
}
2032

2133
@Test
2234
public void testDoubleValidation_valid() {
@@ -34,31 +46,20 @@ public void testDoubleValidation_invalid() {
3446

3547
@Test
3648
public void testJsonIntegerToDouble() throws Exception {
37-
ObjectMapper m = new ObjectMapper();
38-
Stuff a = m.readValue("5", Stuff.class);
49+
Stuff a = MAPPER.readValue("5", Stuff.class);
3950
assertEquals(5, a.value);
4051
}
4152

4253
@Test
4354
public void testJsonLongToDouble() throws Exception {
44-
ObjectMapper m = new ObjectMapper();
4555
assertTrue(LONG_TEST_VALUE > Integer.MAX_VALUE);
46-
Stuff a = m.readValue(String.valueOf(LONG_TEST_VALUE), Stuff.class);
56+
Stuff a = MAPPER.readValue(String.valueOf(LONG_TEST_VALUE), Stuff.class);
4757
assertEquals(LONG_TEST_VALUE, a.value);
4858
}
4959

50-
static class Stuff {
51-
final double value;
52-
53-
Stuff(double value) {
54-
this.value = value;
55-
}
56-
}
57-
5860
@Test
5961
public void testJsonIntegerDeserializationPrefersInt() throws Exception {
60-
ObjectMapper m = new ObjectMapper();
61-
A a = m.readValue("5", A.class);
62+
A a = MAPPER.readValue("5", A.class);
6263
assertEquals(1, a.creatorType);
6364
}
6465

@@ -84,8 +85,7 @@ static class A {
8485

8586
@Test
8687
public void testJsonIntegerDeserializationPrefersLong() throws Exception {
87-
ObjectMapper m = new ObjectMapper();
88-
B a = m.readValue("5", B.class);
88+
B a = MAPPER.readValue("5", B.class);
8989
assertEquals(2, a.creatorType);
9090
}
9191

@@ -107,8 +107,7 @@ static class B {
107107

108108
@Test
109109
public void testJsonIntegerDeserializationPrefersBigInteger() throws Exception {
110-
ObjectMapper m = new ObjectMapper();
111-
C a = m.readValue("5", C.class);
110+
C a = MAPPER.readValue("5", C.class);
112111
assertEquals(3, a.creatorType);
113112
}
114113

@@ -126,8 +125,7 @@ static class C {
126125

127126
@Test
128127
public void testJsonLongDeserializationPrefersLong() throws Exception {
129-
ObjectMapper m = new ObjectMapper();
130-
A2 a = m.readValue(String.valueOf(LONG_TEST_VALUE), A2.class);
128+
A2 a = MAPPER.readValue(String.valueOf(LONG_TEST_VALUE), A2.class);
131129
assertEquals(2, a.creatorType);
132130
}
133131

@@ -153,8 +151,7 @@ static class A2 {
153151

154152
@Test
155153
public void testJsonLongDeserializationPrefersBigInteger() throws Exception {
156-
ObjectMapper m = new ObjectMapper();
157-
B2 a = m.readValue(String.valueOf(LONG_TEST_VALUE), B2.class);
154+
B2 a = MAPPER.readValue(String.valueOf(LONG_TEST_VALUE), B2.class);
158155
assertEquals(3, a.creatorType);
159156
}
160157

@@ -172,10 +169,9 @@ static class B2 {
172169

173170
@Test
174171
public void testJsonIntegerIntoDoubleConstructorThrows() throws Exception {
175-
ObjectMapper m = new ObjectMapper();
176172
try {
177-
m.readValue("5", D.class);
178-
fail();
173+
MAPPER.readValue("5", D.class);
174+
fail("Should not pass");
179175
} catch (ValueInstantiationException e) {
180176
assertTrue(e.getCause() instanceof IllegalArgumentException);
181177
assertEquals("boo", e.getCause().getMessage());
@@ -191,14 +187,12 @@ static final class D {
191187

192188
@Test
193189
public void testJsonLongIntoDoubleConstructorThrows() throws Exception {
194-
ObjectMapper m = new ObjectMapper();
195190
try {
196-
m.readValue(String.valueOf(LONG_TEST_VALUE), D.class);
197-
fail();
191+
MAPPER.readValue(String.valueOf(LONG_TEST_VALUE), D.class);
192+
fail("Should not pass");
198193
} catch (ValueInstantiationException e) {
199194
assertTrue(e.getCause() instanceof IllegalArgumentException);
200195
assertEquals("boo", e.getCause().getMessage());
201196
}
202197
}
203-
204198
}

0 commit comments

Comments
 (0)