CertUtils { public static InputStream toInputStream(String path) throws FileNotFoundException { File certFile = new File(path); if (!certFile.exists()) { URL certResource = CertUtils.class.getClassLoader().getResource(path); if (certResource == null) { throw new FileNotFoundException("File at " + path + " not found"); } certFile = new File(certResource.getFile()); } return new FileInputStream(certFile); }  static InputStream toInputStream(String path); static KeyStore toKeyStore(InputStream keyStoreInputStream, char [] keyStorePassword); static X509Certificate toX509Certificate(InputStream certificateInputStream); static ImmutablePair<PrivateKey, X509Certificate> extractCertificateWithKey(KeyStore keyStore, char [] keyStorePassword); static Set<String> extractApnsTopics(X509Certificate certificate); static String getProviderName();  }
@Test public void toInputStreamWithBadPath() { assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws IOException { try (InputStream stream = toInputStream("dummy.p12")) { assertThat(stream).isNotNull(); } } }).isInstanceOf(FileNotFoundException.class).hasMessage("File at dummy.p12 not found"); }
@Test public void toInputStreamWithValidKeyStore() throws IOException { try (InputStream stream = toInputStream(KEYSTORE_PATH)) { assertThat(stream).isNotNull(); } }