use of org.apache.commons.lang3.builder.ToStringBuilder in project commons-lang by apache.
the class JsonToStringStyleTest method testNestingPerson.
@Test
public void testNestingPerson() {
final Person p = new Person() {
@Override
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());
}
use of org.apache.commons.lang3.builder.ToStringBuilder in project commons-lang by apache.
the class NoFieldNamesToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "Ron Paul";
p.age = 72;
p.smoker = false;
final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
assertEquals(pBaseStr + "[Ron Paul,72,false]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
use of org.apache.commons.lang3.builder.ToStringBuilder in project commons-lang by apache.
the class ShortPrefixToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "John Q. Public";
p.age = 45;
p.smoker = true;
final String pBaseStr = "ToStringStyleTest.Person";
assertEquals(pBaseStr + "[name=John Q. Public,age=45,smoker=true]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
use of org.apache.commons.lang3.builder.ToStringBuilder in project commons-lang by apache.
the class DefaultToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "John Doe";
p.age = 33;
p.smoker = false;
final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
assertEquals(pBaseStr + "[name=John Doe,age=33,smoker=false]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
use of org.apache.commons.lang3.builder.ToStringBuilder in project commons-lang by apache.
the class MultiLineToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "Jane Doe";
p.age = 25;
p.smoker = true;
final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
assertEquals(pBaseStr + "[" + System.lineSeparator() + " name=Jane Doe" + System.lineSeparator() + " age=25" + System.lineSeparator() + " smoker=true" + System.lineSeparator() + "]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
Aggregations