Forgot to add the tests
This commit is contained in:
@@ -52,7 +52,7 @@ public class AnnotationHandler implements HandlerExceptionResolver {
|
|||||||
return new ModelAndView();
|
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.setContentType(MediaType.APPLICATION_XML_VALUE);
|
||||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||||
response.getWriter().write(formatDefaultMessage(thrownException));
|
response.getWriter().write(formatDefaultMessage(thrownException));
|
||||||
|
|||||||
@@ -240,6 +240,21 @@ public class AnnotationHandlerTest {
|
|||||||
|
|
||||||
verify(sut).handleException(mockAnnotation, expectedException, mockResponse);
|
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()
|
@ExceptionHandler()
|
||||||
|
|||||||
Reference in New Issue
Block a user