KeystoreHelper { @VisibleForTesting public byte[] createKeyStore(Collection<PrivateKey> privateKeys) { if (privateKeys.isEmpty()) { return new byte[0]; } KeyStore ks = createKeyStoreInstance(privateKeys); return toBytes(ks); } @VisibleForTesting  KeystoreHelper(); @VisibleForTesting byte[] createKeyStore(Collection<PrivateKey> privateKeys); Certificate[] loadCertificatesForPrivateKey(PrivateKey pk, KeyStore privateKeyStore); KeyStore loadKeyStore(PrivateKey pk); @NotNull char[] getKeystorePassword(); @NotNull String getKeyStoreType();  }
@Test void createEmptyKeyStore() { KeystoreHelper keystoreHelper = new KeystoreHelper(); final byte[] keyStore = keystoreHelper.createKeyStore(emptyList()); assertNotNull(keyStore); assertEquals(0, keyStore.length); }
@Test void tryCreateKeyStoreMissingKeyFile() { KeystoreHelper keystoreHelper = new KeystoreHelper(); assertThrows(KeyStoreCreationException.class, () -> keystoreHelper.createKeyStore(singletonList(createPrivateKey("test", EMPTY, false)))); }
@Test void tryCreateKeyStoreWrongPasswordForKey() { KeystoreHelper keystoreHelper = new KeystoreHelper(); assertThrows(KeyStoreCreationException.class, () -> keystoreHelper.createKeyStore(singletonList(createPrivateKey("test", "test", true)))); }
@Test void tryCreateKeyStoreIncorrectKeyAlias() { KeystoreHelper keystoreHelper = new KeystoreHelper(); assertThrows(KeyStoreCreationException.class, () -> keystoreHelper.createKeyStore(singletonList(createPrivateKey("testXXXX")))); }
@Test void tryCreateKeyStoreMalformedP12File() { KeystoreHelper keystoreHelper = new KeystoreHelper(); assertThrows(KeyStoreCreationException.class, () -> keystoreHelper.createKeyStore(singletonList(createPrivateKey("testInvalid")))); }
@Test void tryCreateKeyStoreInvalidKeyStoreType() { KeystoreHelper keystoreHelper = new KeystoreHelper() { @Override @NotNull public String getKeyStoreType() { return "GW"; } }; assertThrows(KeyStoreCreationException.class, () -> keystoreHelper.createKeyStore(singletonList(createPrivateKey("testInvalid")))); }