### Question:
LoginController implements Controller { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (authenticator.isValidLogin(user, pass)) { return new ModelAndView("frontpage"); } return new ModelAndView("wrongpassword"); }  void setAuthenticator(Authenticator authenticator); ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response);  }### Answer:
@Test public void wrongPasswordShouldRedirectToErrorPage() throws Exception { request.addParameter("j_username", "nosuchusername"); request.addParameter("j_password", "nosuchpassword"); ModelAndView v = controller.handleRequest(request, response); assertEquals("wrongpassword", v.getViewName()); }
@Test public void validLoginForwardsToFrontPageAndStoresUsername() throws Exception { request.addParameter("j_username", VALID_USERNAME); request.addParameter("j_password", CORRECT_PASSWORD); ModelAndView v = controller.handleRequest(request, response); assertEquals("frontpage", v.getViewName()); }