### Question:
SuccessfulQueryHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } } SuccessfulQueryHandler(ObjectMapper securityObjectMapper,
                                  AuthenticationService authenticationService); @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication);  }### Answer:
@Test void shouldSetResponseParameters() throws Exception { httpServletResponse = new MockHttpServletResponse(); TokenAuthentication tokenAuthentication = new TokenAuthentication(USER, jwtToken); httpServletResponse.setStatus(HttpStatus.EXPECTATION_FAILED.value()); assertNotEquals(HttpStatus.OK.value(), httpServletResponse.getStatus()); successfulQueryHandler.onAuthenticationSuccess(httpServletRequest, httpServletResponse, tokenAuthentication); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, httpServletResponse.getContentType()); assertEquals(HttpStatus.OK.value(), httpServletResponse.getStatus()); assertTrue(httpServletResponse.isCommitted()); }
@Test void shouldWriteModelToBody() throws Exception { httpServletResponse = new MockHttpServletResponse(); TokenAuthentication tokenAuthentication = new TokenAuthentication(USER, jwtToken); successfulQueryHandler.onAuthenticationSuccess(httpServletRequest, httpServletResponse, tokenAuthentication); assertNotNull(httpServletResponse.getContentAsString()); String response = httpServletResponse.getContentAsString(); assertTrue(response.contains("\"domain\":\"" + DOMAIN + "\"")); assertTrue(response.contains("\"userId\":\"" + USER + "\"")); assertTrue(response.contains("\"creation\":")); assertTrue(response.contains("\"expiration\":")); }