LoginAction { @RequestMapping("/login") public ModelAndView login(HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); mv.setViewName("login"); LOGGER.debug("enter login action"); KnightCredential credential = credentialResolver.resolveCredential(request); if(credential==null){ String service = request.getParameter(WebConstants.SERVICE_PARAM_NAME); LOGGER.debug("the servcie is "+service); if(!StringUtils.isEmpty(service)){ request.getSession().setAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION, service); } LOGGER.info("no credential, return login page"); return mv; } else{ LoginResult result = ki4soService.login(credential); mv = loginResultToView.loginResultToView(mv, result, request, response); } return mv; }  @RequestMapping("/login") ModelAndView login(HttpServletRequest request,
			HttpServletResponse response);  }
@Test public void unitTestLogin() { LoginAction action = new LoginAction(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); CredentialResolver credentialResolver = Mockito.mock(CredentialResolver.class); action.setCredentialResolver(credentialResolver); request.setParameter(WebConstants.SERVICE_PARAM_NAME, "http: ModelAndView mv = action.login(request, response); Mockito.when(credentialResolver.resolveCredential(request)).thenReturn(null); Assert.assertNotNull(mv); Assert.assertEquals("login", mv.getViewName()); Assert.assertEquals(0, mv.getModel().size()); Assert.assertEquals("http: Credential credential = Mockito.mock(Credential.class); LoginResult loginResult = Mockito.mock(LoginResult.class); ModelAndView result = Mockito.mock(ModelAndView.class); Mockito.when(credentialResolver.resolveCredential(request)).thenReturn(credential); Ki4soService ki4soService = Mockito.mock(Ki4soService.class); action.setKi4soService(ki4soService); LoginResultToView loginResultToView = Mockito.mock(LoginResultToView.class); action.setLoginResultToView(loginResultToView); Mockito.when(ki4soService.login(Mockito.any(Credential.class))).thenReturn(loginResult); Mockito.when(loginResultToView.loginResultToView(Mockito.any(ModelAndView.class), Mockito.any(LoginResult.class), Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class))).thenReturn(result); mv = action.login(request, response); Assert.assertTrue(mv == result); }