ResponseWriter { public void writeErrorResponse(Exception e) { final String stackTrace = StackTrace.getStackTrace(e).replaceAll("\tat", " at<br>"); final String content = "<b>An Exception was thrown!</b><p>" + stackTrace; writer.println("HTTP/1.0 500 Internal Server Error"); writer.println("Content-type: text/html; charset=UTF-8"); appendResponseCommon(content); } ResponseWriter(PrintWriter writer); void writeNotFoundResponse(String line); void writeSuccessfulResponse(String content); void writeErrorResponse(Exception e);  }
@Test public void writeErrorResponse() { String stackTrace = "error stack trace"; Exception e = mock(Exception.class); prepareErrorStackTrace(e, stackTrace); String expectedMessage = createExpectedErrorMessage(stackTrace); testSubject.writeErrorResponse(e); String writtenMessage = stringWriter.toString(); Assert.assertEquals(writtenMessage, expectedMessage); }
@Test public void writeErrorResponseReplacesTabs() { String stackTrace = "error\tat line"; Exception e = mock(Exception.class); prepareErrorStackTrace(e, stackTrace); String expectedStackTrace = "error at<br> line"; String expectedMessage = createExpectedErrorMessage(expectedStackTrace); testSubject.writeErrorResponse(e); String writtenMessage = stringWriter.toString(); Assert.assertEquals(writtenMessage, expectedMessage); }