Query { @Override public String toString() { return string == null ? "" : string; } Query(String string); @Override String toString(); String valueFor(String name); List<String> paramNames(); String show(); boolean eq(Query that);  }
@Test public void toStringIsNullSafe(){ Query testSubject = new Query(null); String result = testSubject.toString(); assertEquals("", result); }
@Test public void toStringDoesWhatYouWouldExpect() { Query testSubject = new Query("?xyz=123&abc=456"); final String result = testSubject.toString(); Assert.assertEquals("?xyz=123&abc=456", result); }