HttpError500Handler extends AbstractHtmlErrorHandler { public HttpError500Handler setReason(final Throwable e) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("<p style=\"color: red; font-weight: bold;\">"); if (!StringUtilities.isEmpty(e.getMessage())) { stringBuilder.append(e.getMessage() + " "); } stringBuilder.append(e.getClass().getName() + "</p>\n") .append("<pre>") .append(exceptionToString(e)) .append("</pre>"); setExplanation(stringBuilder.toString()); return this; } HttpError500Handler(); HttpError500Handler setReason(final Throwable e);  }
@Test public void shouldDisplayClassNameAndExceptionMessage() throws IOException { Exception e = new RuntimeException("FancyExceptionMessage"); httpError500Handler.setReason(e).serve(httpServletResponse); verify(printWriter).write(arg.capture()); String output = arg.getValue(); assertThat(output, containsString(">FancyExceptionMessage java.lang.RuntimeException<")); }
@Test public void shouldDisplayClassNameAndNoExceptionMessageForEmptyValue() throws IOException { Exception e = new RuntimeException(); httpError500Handler.setReason(e).serve(httpServletResponse); verify(printWriter).write(arg.capture()); String output = arg.getValue(); assertThat(output, containsString(">java.lang.RuntimeException<")); }
@Test public void shouldDisplayClassNameAndNoExceptionMessageForNullValue() throws IOException { String msg = null; Exception e = new RuntimeException(msg); httpError500Handler.setReason(e).serve(httpServletResponse); verify(printWriter).write(arg.capture()); String output = arg.getValue(); assertThat(output, containsString(">java.lang.RuntimeException<")); }