@Override public boolean preHandle( HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { List<DispatcherCallback> callbacks = getCallbacks(); // for semi-backwards compatibility for (DispatcherCallback callback : callbacks) { callback.init(request, response); } // the real thing for (DispatcherCallback callback : callbacks) { callback.dispatched(request, response, handler); } return true; }
callback.init(request, response);
@Test public void testCallback() throws Exception { callback.init(anyObject(), anyObject()); expectLastCall(); callback.dispatched(anyObject(), anyObject(), anyObject()); expectLastCall(); callback.finished(anyObject(), anyObject()); expectLastCall(); replay(callback); MockHttpServletResponse response = getAsServletResponse(RestBaseController.ROOT_PATH + "/index.html"); assertEquals(200, response.getStatus()); verify(callback); }
@Test public void testCallbackException() throws Exception { callback.init(anyObject(), anyObject()); expectLastCall(); callback.dispatched(anyObject(), anyObject(), anyObject()); expectLastCall(); callback.exception(anyObject(), anyObject(), anyObject()); expectLastCall(); callback.finished(anyObject(), anyObject()); expectLastCall(); replay(callback); getAsServletResponse(RestBaseController.ROOT_PATH + "/exception?code=400&message=error"); verify(callback); } }