Search in sources :

Example 41 with ToStringBuilder

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());
}
Also used : Person(org.apache.commons.lang3.builder.ToStringStyleTest.Person) Test(org.junit.Test)

Example 42 with ToStringBuilder

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());
}
Also used : Person(org.apache.commons.lang3.builder.ToStringStyleTest.Person) Test(org.junit.Test)

Example 43 with ToStringBuilder

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());
}
Also used : Person(org.apache.commons.lang3.builder.ToStringStyleTest.Person) Test(org.junit.Test)

Example 44 with ToStringBuilder

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());
}
Also used : Person(org.apache.commons.lang3.builder.ToStringStyleTest.Person) Test(org.junit.Test)

Example 45 with ToStringBuilder

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());
}
Also used : Person(org.apache.commons.lang3.builder.ToStringStyleTest.Person) Test(org.junit.Test)

Aggregations

ToStringBuilder (org.apache.commons.lang3.builder.ToStringBuilder)109 Person (org.apache.commons.lang3.builder.ToStringStyleTest.Person)10 Test (org.junit.Test)10 XWikiToStringBuilder (org.xwiki.text.XWikiToStringBuilder)7 Date (java.util.Date)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ToStringStyle (org.apache.commons.lang3.builder.ToStringStyle)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Level (org.apache.logging.log4j.Level)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 MemoryMappedFileAppender (org.apache.logging.log4j.core.appender.MemoryMappedFileAppender)2 RandomAccessFileAppender (org.apache.logging.log4j.core.appender.RandomAccessFileAppender)2 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)2