AzureClientIdCertificateCredentialFactoryImpl implements AsymmetricKeyCredentialFactory { @Override public AsymmetricKeyCredential create(String resource) throws GeneralSecurityException { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); try (FileInputStream inputStream = new FileInputStream( this.keyStorePath)) { keyStore.load(inputStream, this.keyStorePassword.toCharArray()); String alias = keyStore.aliases().nextElement(); KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry)keyStore.getEntry(alias, new KeyStore.PasswordProtection(this.certificatePassword.toCharArray())); AsymmetricKeyCredential credential = AsymmetricKeyCredential.create( this.clientId, privateKeyEntry.getPrivateKey(), (X509Certificate)privateKeyEntry.getCertificate()); return credential; } catch (IOException e) { throw new GeneralSecurityException("Could not load KeyStore file", e); } } AzureClientIdCertificateCredentialFactoryImpl(String clientId, String keyStorePath,
                                                         String keyStorePassword,
                                                         String certificatePassword); @Override AsymmetricKeyCredential create(String resource);  }
@Test void testInvalidFilePath() { AzureClientIdCertificateCredentialFactoryImpl factory = new AzureClientIdCertificateCredentialFactoryImpl(clientId, keystorePath, keystorePassword, certificatePassword); Assertions.assertThrows(GeneralSecurityException.class, () -> factory.create("resource")); }