Skip to content

Instantly share code, notes, and snippets.

@dassiorleando
Created April 3, 2018 15:12
Show Gist options
  • Save dassiorleando/e88aedb74a6682338631a8f30a0eaa37 to your computer and use it in GitHub Desktop.
Save dassiorleando/e88aedb74a6682338631a8f30a0eaa37 to your computer and use it in GitHub Desktop.
Test class to illustrate the safe toString of an object: http://www.dassiorleando.xyz/safely-tostring-a-java-object
@Test
public void safeToStringTest() {
ObjectB objectB = new ObjectB("Fake propB");
ObjectA objectA = new ObjectA("Fake propA", objectB);
String stringObjectA = Objects.toString(objectA);
System.out.println(stringObjectA);
assertNull(objectA.getObjectB2());
assertTrue(stringObjectA.contains("objectB2=null"));
}
@dassiorleando
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment