RedirectionController implements Controller { @Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.info("In RedirectionController."); Map<String, Object> model = new HashMap<String, Object>(); model.put("response", response); return new ModelAndView(viewToRedirectTo, "model", model); }  @Override ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response); void setViewToRedirectTo(String viewToRedirectTo); String getViewToRedirectTo();  }
@Test public void testHandleRequest() throws ServletException, IOException { String expectedPageToRedirectTo = "foopage"; RedirectionController controller = new RedirectionController(); controller.setViewToRedirectTo(expectedPageToRedirectTo); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse); Assert.assertEquals(expectedPageToRedirectTo, modelAndView.getViewName()); Assert.assertNotNull(modelAndView.getModel()); Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model"); Object response = modelMap.get("response"); Assert.assertNotNull(response); Assert.assertEquals(MockHttpServletResponse.class, response.getClass()); }