You cannot, not as a unit test. Annotation is a structure instruction and is not part of your executable code.
The only way to verify this is to download the DispatcherServlet
source code as part of your test (indeed, an integration test) or deploy the application and test it over HTTP.
If you really want to do this in unit test, then consider installing the response code on the HttpServletResponse
manually, instead of using the annotation:
@ExceptionHandler(ExceptionName.class) public String handleIOException(ExceptionName ex, HttpServletRequest request, HttpServletResponse response) { response.setStatus(500) return "errors.messagepage"; }
source share