Forgot to add the tests

This commit is contained in:
Isa Goksu
2012-12-07 12:48:57 -08:00
parent b49d8cc31c
commit afc12ba2ae
2 changed files with 16 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ public class AnnotationHandler implements HandlerExceptionResolver {
return new ModelAndView();
}
private ModelAndView respondWithDefault(final Exception thrownException, final HttpServletResponse response) throws IOException {
protected ModelAndView respondWithDefault(final Exception thrownException, final HttpServletResponse response) throws IOException {
response.setContentType(MediaType.APPLICATION_XML_VALUE);
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
response.getWriter().write(formatDefaultMessage(thrownException));

View File

@@ -240,6 +240,21 @@ public class AnnotationHandlerTest {
verify(sut).handleException(mockAnnotation, expectedException, mockResponse);
}
@Test public void resolveException_ShouldReturnDefaultErrorMessage_WhenUncheckedExceptionIsGiven() throws Exception {
final NullPointerException expectedException = mock(NullPointerException.class);
final HttpServletResponse mockResponse = mock(HttpServletResponse.class);
final PrintWriter mockPrinter = mock(PrintWriter.class);
when(mockResponse.getWriter()).thenReturn(mockPrinter);
final AnnotationHandler sut = spy(new AnnotationHandler());
doReturn(null).when(sut).getAnnotationFrom(expectedException);
final ModelAndView view = sut.resolveException(null, mockResponse, null, expectedException);
verify(sut).respondWithDefault(expectedException, mockResponse);
}
}
@ExceptionHandler()