Utils { public static KeyStore createKeyStore(final String athenzPublicCert, final String athenzPrivateKey) throws FileNotFoundException, IOException, InterruptedException, KeyRefresherException { if (athenzPublicCert == null || athenzPublicCert.isEmpty()) { throw new FileNotFoundException("athenzPublicCert can not be empty"); } if (athenzPrivateKey == null || athenzPrivateKey.isEmpty()) { throw new FileNotFoundException("athenzPrivateKey can not be empty"); } final Supplier<InputStream> certFileSupplier; final Supplier<InputStream> keyFileSupplier; final Supplier<String> certLocationSupplier = () -> athenzPublicCert; final Supplier<String> keyLocationSupplier = () -> athenzPrivateKey; if (Paths.get(athenzPublicCert).isAbsolute() && Paths.get(athenzPrivateKey).isAbsolute()) { final File certFile = new File(athenzPublicCert); final File keyFile = new File(athenzPrivateKey); certFileSupplier = inputStreamSupplierFromFile(certFile); keyFileSupplier = inputStreamSupplierFromFile(keyFile); long startTime = System.currentTimeMillis(); while (!certFile.exists() || !keyFile.exists()) { long durationInMillis = System.currentTimeMillis() - startTime; if (durationInMillis > KEY_WAIT_TIME_MILLIS) { throw new KeyRefresherException("Keyfresher waited " + durationInMillis + " ms for valid public cert: " + athenzPublicCert + " or private key: " + athenzPrivateKey + " files. Giving up."); } LOG.error("Missing Athenz public certificate {} or private key {} files. Waiting {} ms", athenzPublicCert, athenzPrivateKey, durationInMillis); Thread.sleep(1000); } } else { certFileSupplier = inputStreamSupplierFromResource(athenzPublicCert); keyFileSupplier = inputStreamSupplierFromResource(athenzPrivateKey); } try { return createKeyStore(certFileSupplier, certLocationSupplier, keyFileSupplier, keyLocationSupplier); } catch (UncheckedIOException e) { throw e.getCause(); } }  static KeyStore getKeyStore(final String jksFilePath); static KeyStore getKeyStore(final String jksFilePath, final char[] password); static KeyManager[] getKeyManagers(final String athenzPublicCert, final String athenzPrivateKey); static KeyRefresher generateKeyRefresher(final String trustStorePath,
                                                    final String athenzPublicCert, final String athenzPrivateKey); static KeyRefresher generateKeyRefresher(final String trustStorePath,
                                                    final String trustStorePassword, final String athenzPublicCert, final String athenzPrivateKey); static KeyRefresher generateKeyRefresher(final String trustStorePath,
                                                    final char[] trustStorePassword, final String athenzPublicCert, final String athenzPrivateKey); static KeyRefresher generateKeyRefresher(final String trustStorePath,
                                                    final char[] trustStorePassword, final String athenzPublicCert,
                                                    final String athenzPrivateKey, final KeyRefresherListener keyRefresherListener); static KeyRefresher generateKeyRefresherFromCaCert(final String caCertPath,
                                                              final String athenzPublicCert, final String athenzPrivateKey); static SSLContext buildSSLContext(KeyManagerProxy keyManagerProxy,
                                             TrustManagerProxy trustManagerProxy); static KeyStore createKeyStore(final String athenzPublicCert, final String athenzPrivateKey); static KeyStore createKeyStoreFromPems(
            final String athenzPublicCertPem,
            final String athenzPrivateKeyPem); static KeyStore createKeyStore(
            final Supplier<InputStream> athenzPublicCertInputStream,
            final Supplier<String> athenzPublicCertLocationSupplier,
            final Supplier<InputStream> athenzPrivateKeyInputStream,
            final Supplier<String> athenzPrivateKeyLocationSupplier); static KeyStore generateTrustStore(InputStream inputStream);  }
@Test (expected = FileNotFoundException.class) public void createKeyStoreTest() throws FileNotFoundException, IOException, KeyRefresherException, InterruptedException { Utils.createKeyStore(null, null); Assert.fail("Should have thrown FileNotFoundException."); }