### Question:
ApimlX509Filter extends X509AuthenticationFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { categorizeCerts(request); super.doFilter(request, response, chain); }  @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }### Answer:
@Test void givenNoCertificates_thenDontUpdate_whenCallFilter() throws IOException, ServletException { ApimlX509Filter filter = new ApimlX509Filter(Collections.emptySet()); filter.doFilter(request, response, chain); assertNull(request.getAttribute("javax.servlet.request.X509Certificate")); verify(chain, times(1)).doFilter(request, response); }
@Test void giveCertificates_thenRemoveForeign_whenCallFilter() throws IOException, ServletException { ApimlX509Filter filter = new ApimlX509Filter(new HashSet<>(Arrays.asList( X509Utils.correctBase64("apimlCert1"), X509Utils.correctBase64("apimlCert2") ))); filter.setAuthenticationDetailsSource(mock(AuthenticationDetailsSource.class)); filter.setAuthenticationManager(mock(AuthenticationManager.class)); X509Certificate[] certificates = new X509Certificate[]{ X509Utils.getCertificate(X509Utils.correctBase64("foreignCert1")), X509Utils.getCertificate(X509Utils.correctBase64("apimlCert1")), X509Utils.getCertificate(X509Utils.correctBase64("foreignCert2")), X509Utils.getCertificate(X509Utils.correctBase64("apimlCert2")) }; request.setAttribute("javax.servlet.request.X509Certificate", certificates); filter.doFilter(request, response, chain); X509Certificate[] filtered = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); assertNotNull(filtered); assertEquals(2, filtered.length); assertSame(certificates[1], filtered[0]); assertSame(certificates[3], filtered[1]); verify(chain, times(1)).doFilter(request, response); }