KeyStoreCredentialResolverBuilder { public CredentialResolver build() throws IOException, GeneralSecurityException { final KeyStore ks = KeyStore.getInstance(type); try (InputStream is = open()) { ks.load(is, password != null ? password.toCharArray() : null); } return new KeyStoreCredentialResolver(ks, keyPasswords); } KeyStoreCredentialResolverBuilder(File file);  KeyStoreCredentialResolverBuilder(Path path);  KeyStoreCredentialResolverBuilder(ClassLoader classLoader, String resourcePath); KeyStoreCredentialResolverBuilder type(String type); KeyStoreCredentialResolverBuilder password(@Nullable String password); KeyStoreCredentialResolverBuilder keyPassword(String name, String password); KeyStoreCredentialResolverBuilder keyPasswords(Map<String, String> keyPasswords); CredentialResolver build();  }
@Test public void expectSuccessWithFile() throws Exception { final File file = folder.newFile(); assertThat(file.length()).isZero(); final KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(null, null); keyStore.store(new FileOutputStream(file), "".toCharArray()); assertThat(file.length()).isGreaterThan(0); assertThat(file.canRead()).isTrue(); assertThat(file.exists()).isTrue(); new KeyStoreCredentialResolverBuilder(file).build(); }
@Test public void expectSuccessWithResource() throws Exception { new KeyStoreCredentialResolverBuilder(getClass().getClassLoader(), "keystore/test.jks").build(); }
@Test public void expectNotFound() throws Exception { assertThatThrownBy( () -> new KeyStoreCredentialResolverBuilder(new File("/not_exist")).build()) .isInstanceOf(FileNotFoundException.class); assertThatThrownBy( () -> new KeyStoreCredentialResolverBuilder(getClass().getClassLoader(), "not_exist").build()) .isInstanceOf(FileNotFoundException.class) .hasMessageContaining("Resource not found"); }