Problem { @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(this.getStatus()).append(": "); if (this.getCode() != DEFAULT_CODE) { sb.append("(").append(this.getCode()).append(") "); } sb.append(this.getMessageString()); if (this.getResource() != null) { sb.append(" Resource=\"").append(this.getResource()).append("\""); } if (this.getLocation() != null) { sb.append(" At \"").append(this.getLocation()).append("\""); } if (this.getThrowable() != null) { sb.append(" (threw ").append(this.getThrowable().getLocalizedMessage()).append(")"); } return sb.toString(); } Problem( Status status,
                    int code,
                    I18n message,
                    Object[] params,
                    String resource,
                    String location,
                    Throwable throwable ); int getCode(); String getLocation(); String getMessageString(); I18n getMessage(); Object[] getParameters(); String getResource(); Status getStatus(); Throwable getThrowable(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override String toString(); static final int DEFAULT_CODE; }
@Test public void shouldHaveToString() { assertThat(error.toString(), is("ERROR: (1) " + message.text("message") + " Resource=\"" + resource + "\" At \"" + location + "\" (threw " + throwable.getLocalizedMessage() + ")")); }
@Test public void shouldHaveToStringWithoutDefaultCode() { error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"message"}, null, null, null); assertThat(error.toString(), is("ERROR: " + message.text("message"))); }