AbstractHtmlErrorHandler extends AbstractPlainTextHttpErrorHandler { @Override public void serve(final HttpServletResponse response) throws IOException { response.setStatus(getStatus()); response.setContentType("text/html"); if (StringUtilities.isEmpty(errorDocumentPath)) { serveDocument(response); } else { File file = new File(errorDocumentPath); if (file.exists()) { serveFile(response, file); } else { throw new IOException(getStatus() + " occurred, specified error handler (" + errorDocumentPath + ") was not found."); } } } AbstractHtmlErrorHandler(final String status,
                                    final String message,
                                    final String explanation,
                                    final String errorDocumentPath); @Override void serve(final HttpServletResponse response);  }
@Test(expected = IOException.class) public void shouldThrowExceptionWhenDocumentPathIsMissing() throws Exception { AbstractHtmlErrorHandler handler = new SampleHtmlErrorHanlder("500", "", "", "/tmp/nonexistend"); handler.serve(response); }
@Test public void shouldServeBuiltinDocument() throws Exception { AbstractHtmlErrorHandler handler = new SampleHtmlErrorHanlder("500", "MSG_TOKEN", "EXPLANATION_TOKEN", null); handler.serve(response); assertThat(response.getStatus(), containsString("500")); assertThat(outputStream.toString(), containsString("MSG_TOKEN")); assertThat(outputStream.toString(), containsString("EXPLANATION_TOKEN")); }
@Test public void shouldServeExternalDocument() throws IOException { File file = FileUtils.writeToTempFile("FILE_TOKEN"); AbstractHtmlErrorHandler handler = new SampleHtmlErrorHanlder("", "", "", file.getAbsolutePath()); handler.serve(response); assertThat(outputStream.toString(), containsString("FILE_TOKEN")); }