### Question:
AbstractRestApi { @ExceptionHandler(AccessDeniedException.class) public void handleAccessDeniedException(Exception ex, HttpServletRequest request, HttpServletResponse response) { logger.info("AccessDeniedException: " + request.getUserPrincipal().getName() + " attempted to access resource " + request.getRequestURL(), ex); response.setStatus(HttpStatus.FORBIDDEN.value()); }  @ExceptionHandler(AccessDeniedException.class) void handleAccessDeniedException(Exception ex, HttpServletRequest request, HttpServletResponse response); @ExceptionHandler(Exception.class) String handleException(Exception ex, HttpServletRequest request, HttpServletResponse response);  }### Answer:
@Test public void testHandleAccessDeniedException() { Principal principal = createMock(Principal.class); request.setUserPrincipal(principal); AccessDeniedException ade = new AccessDeniedException("error"); expect(principal.getName()).andReturn("theuser"); replay(principal); abstractRestApiImpl.handleAccessDeniedException(ade, request, response); assertThat(response.getStatus(), is(HttpStatus.FORBIDDEN.value())); verify(principal); }