Problem implements Serializable { @Override public String toString() { StringBuilder sb = new StringBuilder(); if (getDetail() != null) { sb.append(getDetail()); } else if (getTitle() != null) { sb.append(getTitle()); } else { sb.append(getType()); } List<Problem> subproblems = getSubProblems(); if (!subproblems.isEmpty()) { sb.append(" ("); boolean first = true; for (Problem sub : subproblems) { if (!first) { sb.append(" ‒ "); } sb.append(sub.toString()); first = false; } sb.append(')'); } return sb.toString(); } Problem(JSON problem, URL baseUrl); URI getType(); @Nullable String getTitle(); @Nullable String getDetail(); @Nullable URI getInstance(); @Nullable Identifier getIdentifier(); List<Problem> getSubProblems(); JSON asJSON(); @Override String toString();  }
@Test public void testToString() { URL baseUrl = url("https: URI typeUri = URI.create("urn:ietf:params:acme:error:malformed"); JSONBuilder jb = new JSONBuilder(); jb.put("type", typeUri); Problem p1 = new Problem(jb.toJSON(), baseUrl); assertThat(p1.toString(), is(typeUri.toString())); jb.put("title", "Some of the identifiers requested were rejected"); Problem p2 = new Problem(jb.toJSON(), baseUrl); assertThat(p2.toString(), is("Some of the identifiers requested were rejected")); jb.put("detail", "Identifier \"abc12_\" is malformed"); Problem p3 = new Problem(jb.toJSON(), baseUrl); assertThat(p3.toString(), is("Identifier \"abc12_\" is malformed")); }