### Question:
ChaosAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) { ChaosWebSecurity.logSuccessfulRequest("Authentication success", httpServletRequest); SavedRequest request = requestCache.getRequest(httpServletRequest, httpServletResponse); if (request == null) { clearAuthenticationAttributes(httpServletRequest); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && !targetUrlParameter.isEmpty())) { requestCache.removeRequest(httpServletRequest, httpServletResponse); clearAuthenticationAttributes(httpServletRequest); return; } clearAuthenticationAttributes(httpServletRequest); } @Autowired  ChaosAuthenticationSuccessHandler();   ChaosAuthenticationSuccessHandler(HttpSessionRequestCache requestCache); @Override void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication);  }### Answer:
@Test public void onAuthenticationSuccessWithNullSession () { doReturn(null).when(httpSessionRequestCache).getRequest(request, response); chaosAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, exception); verify(httpSessionRequestCache, never()).removeRequest(request, response); }
@Test public void onAuthenticationSuccessWithTargetedUrl () { chaosAuthenticationSuccessHandler.setAlwaysUseDefaultTargetUrl(true); chaosAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, exception); verify(httpSessionRequestCache, times(1)).removeRequest(request, response); }
@Test public void onAuthenticationSuccessWithNullTargetUrl () { chaosAuthenticationSuccessHandler.setAlwaysUseDefaultTargetUrl(false); chaosAuthenticationSuccessHandler.setTargetUrlParameter(null); chaosAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, exception); verify(httpSessionRequestCache, never()).removeRequest(request, response); }
@Test public void onAuthenticationSuccessWithEmptyTargetUrl () { chaosAuthenticationSuccessHandler.setAlwaysUseDefaultTargetUrl(false); ReflectionTestUtils.setField(chaosAuthenticationSuccessHandler, "targetUrlParameter", ""); chaosAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, exception); verify(httpSessionRequestCache, never()).removeRequest(request, response); }
@Test public void onAuthenticationSuccessWithTargetUrlParameter () { chaosAuthenticationSuccessHandler.setAlwaysUseDefaultTargetUrl(false); chaosAuthenticationSuccessHandler.setTargetUrlParameter("/not empty!"); chaosAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, exception); verify(httpSessionRequestCache, times(1)).removeRequest(request, response); }