### Question:
SuccessfulAuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler { public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { JCUser user = (JCUser) authentication.getPrincipal(); userService.updateLastLoginTime(user); logger.info("JCUser logged in: " + user.getUsername()); String languageCode = user.getLanguage().getLanguageCode(); LocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setLocale(request, response, user.getLanguage().getLocale()); Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, languageCode); cookie.setPath("/"); response.addCookie(cookie); super.onAuthenticationSuccess(request, response, authentication); } SuccessfulAuthenticationHandler(UserService userService); void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                                        Authentication authentication);  }### Answer:
@Test public void testOnAuthenticationSuccess() throws Exception { JCUser user = new JCUser("username", "email", "password"); Authentication auth = mock(Authentication.class); when(auth.getPrincipal()).thenReturn(user); handler.onAuthenticationSuccess(new MockHttpServletRequest(), new MockHttpServletResponse(), auth); verify(userService).updateLastLoginTime(user); }