### Question:
AmbariBasicAuthenticationFilter extends BasicAuthenticationFilter implements AmbariAuthenticationFilter { @Override protected void onSuccessfulAuthentication(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Authentication authResult) throws IOException { if (eventHandler != null) { eventHandler.onSuccessfulAuthentication(this, servletRequest, servletResponse, authResult); } } AmbariBasicAuthenticationFilter(AuthenticationManager authenticationManager,
                                         AmbariEntryPoint ambariEntryPoint,
                                         AmbariAuthenticationEventHandler eventHandler); @Override boolean shouldApply(HttpServletRequest httpServletRequest); @Override boolean shouldIncrementFailureCount(); @Override void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain);  }### Answer:
@Test public void testDoFilterSuccessful() throws IOException, ServletException { Capture<? extends AmbariAuthenticationFilter> captureFilter = newCapture(CaptureType.ALL); HttpServletRequest request = createNiceMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); HttpSession session = createMock(HttpSession.class); FilterChain filterChain = createMock(FilterChain.class); expect(request.getHeader("Authorization")).andReturn("Basic YWRtaW46YWRtaW4=").once(); expect(request.getRemoteAddr()).andReturn("1.2.3.4").once(); expect(request.getSession(false)).andReturn(session).once(); expect(session.getId()).andReturn("sessionID").once(); expect(authenticationManager.authenticate(anyObject(Authentication.class))) .andAnswer(new IAnswer<Authentication>() { @Override public Authentication answer() throws Throwable { return (Authentication) getCurrentArguments()[0]; } }) .anyTimes(); eventHandler.beforeAttemptAuthentication(capture(captureFilter), eq(request), eq(response)); expectLastCall().once(); eventHandler.onSuccessfulAuthentication(capture(captureFilter), eq(request), eq(response), anyObject(Authentication.class)); expectLastCall().once(); filterChain.doFilter(request, response); expectLastCall().once(); replayAll(); AmbariAuthenticationFilter filter = new AmbariBasicAuthenticationFilter(authenticationManager, entryPoint, eventHandler); filter.doFilter(request, response, filterChain); verifyAll(); List<? extends AmbariAuthenticationFilter> capturedFilters = captureFilter.getValues(); for (AmbariAuthenticationFilter capturedFiltered : capturedFilters) { Assert.assertSame(filter, capturedFiltered); } }