ValueObject { @Override public String toString() { StringBuilder buf = new StringBuilder(getClass().getSimpleName()); buf.append(" {"); Field[] fields = getValueFields(getClass()); int i = 0; for (Object value : valueList()) { if (i > 0) { buf.append(", "); } buf.append(fields[i++].getName()).append('=').append(value); } buf.append('}'); return buf.toString(); }  @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testToString() { assertEquals("Dog {age=1, sex=male, name=tom}", new Dog("male", 1, "tom").toString()); assertEquals("Person {name=ben}", new Person("ben").toString()); }