Skip to content

Commit 20898cf

Browse files
committed
minor test refactoring
1 parent f478855 commit 20898cf

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.jackson.databind.deser.filter;
22

3+
import java.util.Set;
4+
35
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
46
import com.fasterxml.jackson.annotation.JsonProperty;
57

@@ -12,33 +14,57 @@ static class Person {
1214

1315
@JsonProperty("person_z") // renaming this to person_p works
1416
@JsonIgnoreProperties({"person_z"}) // renaming this to person_p works
15-
// public Set<Person> personZ;
1617
public Person personZ;
1718
}
1819

20+
static class Persons {
21+
public String name;
22+
23+
@JsonProperty("person_z") // renaming this to person_p works
24+
@JsonIgnoreProperties({"person_z"}) // renaming this to person_p works
25+
public Set<Persons> personZ;
26+
}
27+
28+
/*
29+
/**********************************************************************
30+
/* Test methods
31+
/**********************************************************************
32+
*/
33+
34+
private final ObjectMapper MAPPER = newObjectMapper();
35+
1936
public void testRecursiveForDeser() throws Exception
2037
{
2138
String st = aposToQuotes("{ 'name': 'admin',\n"
22-
// + " 'person_z': [ { 'name': 'admin' } ]"
23-
+ " 'person_z': { 'name': 'admin' }"
39+
+ " 'person_z': { 'name': 'wyatt' }"
2440
+ "}");
41+
Person result = MAPPER.readValue(st, Person.class);
42+
assertEquals("admin", result.name);
43+
assertNotNull(result.personZ);
44+
assertEquals("wyatt", result.personZ.name);
45+
}
2546

26-
ObjectMapper mapper = newObjectMapper();
27-
Person result = mapper.readValue(st, Person.class);
47+
public void testRecursiveWithCollectionDeser() throws Exception
48+
{
49+
String st = aposToQuotes("{ 'name': 'admin',\n"
50+
+ " 'person_z': [ { 'name': 'Foor' }, { 'name' : 'Bar' } ]"
51+
+ "}");
52+
Persons result = MAPPER.readValue(st, Persons.class);
2853
assertEquals("admin", result.name);
54+
assertNotNull(result.personZ);
55+
assertEquals(2, result.personZ.size());
2956
}
3057

3158
public void testRecursiveForSer() throws Exception
3259
{
33-
ObjectMapper mapper = newObjectMapper();
3460
Person input = new Person();
3561
input.name = "Bob";
3662
Person p2 = new Person();
3763
p2.name = "Bill";
3864
input.personZ = p2;
3965
p2.personZ = input;
4066

41-
String json = mapper.writeValueAsString(input);
67+
String json = MAPPER.writeValueAsString(input);
4268
assertNotNull(json);
4369
}
4470
}

0 commit comments

Comments
 (0)