HttpCrlFetcher implements CrlFetcher { protected X509CRL httpDownload(String url) throws CertificateValidationException { try { CertificateFactory cf = CertificateFactory.getInstance("x509", BouncyCastleProvider.PROVIDER_NAME); return (X509CRL)cf.generateCRL(URI.create(url).toURL().openStream()); } catch (IOException | CRLException | CertificateException | NoSuchProviderException e) { throw new CertificateValidationException(String.format("Failed to download CRL '%s' (%s)", url, e.getMessage()), e); } } HttpCrlFetcher(Set<X509Certificate> trustAnchors); @Override X509CRL get(String url);  }
@Test void throwsCertValidationExceptionBouncyCastleIsNotPresent() throws Exception { Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); Set<X509Certificate> trustedSet = new HashSet<>(); trustedSet.add(certificate); HttpCrlFetcher crlFetcher = new HttpCrlFetcher(trustedSet); CertificateValidationException certificateValidationException = Assertions.assertThrows(CertificateValidationException.class, () -> crlFetcher.httpDownload("mock-address")); Assertions.assertTrue(certificateValidationException.toString() .contains("Failed to download CRL 'mock-address'")); }