Skip to content

Commit a018ddf

Browse files
committed
minor test cleanup
1 parent 65f1e89 commit a018ddf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/PolymorphicIdTest.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ static class NestedImpl implements Nested {
2222
public String value;
2323
}
2424

25+
private final ObjectMapper MAPPER = newObjectMapper();
26+
2527
@Test
2628
public void testPolymorphicType() throws Exception
2729
{
2830
// first, with value
2931
String YAML = "nested:\n"
3032
+" type: single\n"
3133
+" value: whatever";
32-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
33-
Wrapper top = mapper.readValue(YAML, Wrapper.class);
34+
Wrapper top = MAPPER.readValue(YAML, Wrapper.class);
3435
assertNotNull(top);
3536
assertEquals(NestedImpl.class, top.nested.getClass());
3637
assertEquals("whatever", ((NestedImpl) top.nested).value);
3738

3839
// then without value
3940
YAML = "nested:\n"
4041
+" type: single";
41-
top = mapper.readValue(YAML, Wrapper.class);
42+
top = MAPPER.readValue(YAML, Wrapper.class);
4243
assertNotNull(top);
4344
assertEquals(NestedImpl.class, top.nested.getClass());
4445
assertNull("whatever", ((NestedImpl) top.nested).value);
@@ -49,26 +50,27 @@ public void testNativePolymorphicType() throws Exception {
4950
String YAML = "nested: !single\n"
5051
+" value: foobar\n"
5152
;
52-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
53-
Wrapper top = mapper.readValue(YAML, Wrapper.class);
53+
Wrapper top = MAPPER.readValue(YAML, Wrapper.class);
5454
assertNotNull(top);
5555
assertNotNull(top.nested);
5656
assertEquals(NestedImpl.class, top.nested.getClass());
5757
assertEquals("foobar", ((NestedImpl) top.nested).value);
5858

59-
YAML = "nested: !single { }\n";
60-
top = mapper.readValue(YAML, Wrapper.class);
59+
top = MAPPER.readValue("nested: !single { }\n", Wrapper.class);
6160
assertNotNull(top);
6261
assertNotNull(top.nested);
6362
assertEquals(NestedImpl.class, top.nested.getClass());
63+
}
64+
65+
@Test
66+
public void testNativePolymorphicTypeFromEmpty() throws Exception {
6467
// no value specified, empty
6568

6669
// And third possibility; trickier, since YAML contains empty String,
6770
// and not Object; so we need to allow coercion
68-
ObjectReader r = mapper.readerFor(Wrapper.class)
71+
ObjectReader r = MAPPER.readerFor(Wrapper.class)
6972
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
70-
YAML = "nested: !single\n";
71-
top = r.readValue(YAML);
73+
Wrapper top = r.readValue("nested: !single\n");
7274
assertNotNull(top);
7375

7476
// and as a result, get null

0 commit comments

Comments
 (0)