add testNestingPerson case to JsonToStringStyleTest.java

This commit is contained in:
Jack 2015-05-01 14:10:22 +08:00
parent 6d23e85570
commit 2584b4a0ef
1 changed files with 40 additions and 0 deletions

View File

@ -230,6 +230,30 @@ public class JsonToStringStyleTest {
.toString()); .toString());
} }
@Test
public void testNestingPerson() {
final Person p = new Person(){
public String toString(){
return new ToStringBuilder(this).append("name", this.name)
.append("age", this.age).append("smoker", this.smoker)
.toString();
}
};
p.name = "Jane Doe";
p.age = 25;
p.smoker = true;
final NestingPerson nestP = new NestingPerson();
nestP.pid="#1@Jane";
nestP.person = p;
assertEquals(
"{\"pid\":\"#1@Jane\",\"person\":{\"name\":\"Jane Doe\",\"age\":25,\"smoker\":true}}",
new ToStringBuilder(nestP).append("pid", nestP.pid)
.append("person", nestP.person)
.toString());
}
@Test @Test
public void testLong() { public void testLong() {
@ -337,4 +361,20 @@ public class JsonToStringStyleTest {
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
} }
} }
/**
* An object with nested object structures used to test {@link JsonToStringStyle}.
*
*/
static class NestingPerson {
/**
* Test String field.
*/
String pid;
/**
* Test nested object field.
*/
Person person;
}
} }