### Question:
SslUtil { static KeyStore createTruststoreFromPemKey(String certificateAsString) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException { try (PEMParser parser = new PEMParser(new StringReader(certificateAsString))) { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); int i = 0; X509Certificate certificate; while ((certificate = parseCert(parser)) != null) { keyStore.setCertificateEntry("cert_" + i, certificate); i += 1; } return keyStore; } } private  SslUtil();   }### Answer:
@Test public void readCustomCa() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { String pemContent = IOUtils.toString(getClass().getResourceAsStream("/test.pem"), "UTF-8"); KeyStore truststore = SslUtil.createTruststoreFromPemKey(pemContent); assertThat(truststore).isNotNull(); List<Certificate> certificates = extractCertificates(truststore); assertThat(certificates).hasSize(1); }
@Test public void readLetsEncryptCaIdenTrust() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { String pemContent = IOUtils.toString(getClass().getResourceAsStream("/le-ca-x3-iden-trust.pem"), "UTF-8"); KeyStore truststore = SslUtil.createTruststoreFromPemKey(pemContent); assertThat(truststore).isNotNull(); List<Certificate> certificates = extractCertificates(truststore); assertThat(certificates).hasSize(1); }
@Test public void readLetsEncryptCaIsrg() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { String pemContent = IOUtils.toString(getClass().getResourceAsStream("/le-ca-x3-isrg-x1.pem"), "UTF-8"); KeyStore truststore = SslUtil.createTruststoreFromPemKey(pemContent); assertThat(truststore).isNotNull(); List<Certificate> certificates = extractCertificates(truststore); assertThat(certificates).hasSize(1); }