### Question:
KeycloakAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter implements ApplicationContextAware { @Override protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException { super.unsuccessfulAuthentication(request, response, failed); } KeycloakAuthenticationProcessingFilter(AuthenticationManager authenticationManager);  KeycloakAuthenticationProcessingFilter(AuthenticationManager authenticationManager, RequestMatcher
            requiresAuthenticationRequestMatcher); @Override void afterPropertiesSet(); @Override Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response); @Override void setApplicationContext(ApplicationContext applicationContext); void setAdapterTokenStoreFactory(AdapterTokenStoreFactory adapterTokenStoreFactory); @Override final void setAllowSessionCreation(boolean allowSessionCreation); @Override final void setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication); void setRequestAuthenticatorFactory(RequestAuthenticatorFactory requestAuthenticatorFactory); static final String AUTHORIZATION_HEADER; static final RequestMatcher DEFAULT_REQUEST_MATCHER; }### Answer:
@Test public void testUnsuccessfulAuthenticationInteractive() throws Exception { AuthenticationException exception = new BadCredentialsException("OOPS"); filter.unsuccessfulAuthentication(request, response, exception); verify(failureHandler).onAuthenticationFailure(eq(request), eq(response), eq(exception)); }
@Test public void testUnsuccessfulAuthenticatioBearer() throws Exception { AuthenticationException exception = new BadCredentialsException("OOPS"); this.setBearerAuthHeader(request); filter.unsuccessfulAuthentication(request, response, exception); verify(failureHandler).onAuthenticationFailure(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationException.class)); }
@Test public void testUnsuccessfulAuthenticatioBasicAuth() throws Exception { AuthenticationException exception = new BadCredentialsException("OOPS"); this.setBasicAuthHeader(request); filter.unsuccessfulAuthentication(request, response, exception); verify(failureHandler).onAuthenticationFailure(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationException.class)); }
@Test public void testDefaultFailureHanlder() throws Exception { AuthenticationException exception = new BadCredentialsException("OOPS"); filter.setAuthenticationFailureHandler(keycloakFailureHandler); filter.unsuccessfulAuthentication(request, response, exception); verify(response).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED), any(String.class)); }