@Test public void toString_shows_class_name_and_fields() { assertThat("no fields", Boilerplate.toString(getClass()), is("BoilerplateTest()")); assertThat("one field", Boilerplate.toString(getClass(), "foo"), is("BoilerplateTest(foo)")); assertThat("many fields", Boilerplate.toString(getClass(), "bar", 42), is("BoilerplateTest(bar, 42)")); assertThat("inner class", Boilerplate.toString(InnerClass.class), is("BoilerplateTest$InnerClass()")); }
public static String toString(Class<?> clazz, Object... fields) { StringBuilder sb = new StringBuilder(); sb.append(nameWithoutPackage(clazz)); sb.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) { sb.append(", "); } sb.append(fields[i]); } sb.append(')'); return sb.toString(); }
Boilerplate { public static String toString(Class<?> clazz, Object... fields) { StringBuilder sb = new StringBuilder(); sb.append(nameWithoutPackage(clazz)); sb.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) { sb.append(", "); } sb.append(fields[i]); } sb.append(')'); return sb.toString(); } }
Boilerplate { public static String toString(Class<?> clazz, Object... fields) { StringBuilder sb = new StringBuilder(); sb.append(nameWithoutPackage(clazz)); sb.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) { sb.append(", "); } sb.append(fields[i]); } sb.append(')'); return sb.toString(); }  }
Boilerplate { public static String toString(Class<?> clazz, Object... fields) { StringBuilder sb = new StringBuilder(); sb.append(nameWithoutPackage(clazz)); sb.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) { sb.append(", "); } sb.append(fields[i]); } sb.append(')'); return sb.toString(); }  static RuntimeException rethrow(Throwable t); static String toString(Class<?> clazz, Object... fields); }
Boilerplate { public static String toString(Class<?> clazz, Object... fields) { StringBuilder sb = new StringBuilder(); sb.append(nameWithoutPackage(clazz)); sb.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) { sb.append(", "); } sb.append(fields[i]); } sb.append(')'); return sb.toString(); }  static RuntimeException rethrow(Throwable t); static String toString(Class<?> clazz, Object... fields);  }