@Test public void testCreateForAliasWithoutPrivateKey() throws KeyStoreException { new Expectations() { { keyStore.getCertificate(ALIAS); result = null; } }; EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStore); EncryptionService encryptionService = factory.create(ALIAS); Assertions.assertThat(encryptionService).isNotNull(); new Verifications() { { new EncryptionServiceImpl(ALIAS, publicKey, null); } }; }
EncryptionService create(String alias, char[] password) { PublicKey pk = getPublicKey(alias); Key key; try { key = this.keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { throw SeedException.wrap(e, CryptoErrorCode.UNRECOVERABLE_KEY); } catch (KeyStoreException e) { throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION); } catch (NoSuchAlgorithmException e) { throw SeedException.wrap(e, CryptoErrorCode.ALGORITHM_CANNOT_BE_FOUND); } return new EncryptionServiceImpl(alias, pk, key); }
EncryptionServiceFactory { EncryptionService create(String alias, char[] password) { PublicKey pk = getPublicKey(alias); Key key; try { key = this.keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { throw SeedException.wrap(e, CryptoErrorCode.UNRECOVERABLE_KEY); } catch (KeyStoreException e) { throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION); } catch (NoSuchAlgorithmException e) { throw SeedException.wrap(e, CryptoErrorCode.ALGORITHM_CANNOT_BE_FOUND); } return new EncryptionServiceImpl(alias, pk, key); } }
EncryptionServiceFactory { EncryptionService create(String alias, char[] password) { PublicKey pk = getPublicKey(alias); Key key; try { key = this.keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { throw SeedException.wrap(e, CryptoErrorCode.UNRECOVERABLE_KEY); } catch (KeyStoreException e) { throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION); } catch (NoSuchAlgorithmException e) { throw SeedException.wrap(e, CryptoErrorCode.ALGORITHM_CANNOT_BE_FOUND); } return new EncryptionServiceImpl(alias, pk, key); } EncryptionServiceFactory(KeyStore keyStore); }
EncryptionServiceFactory { EncryptionService create(String alias, char[] password) { PublicKey pk = getPublicKey(alias); Key key; try { key = this.keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { throw SeedException.wrap(e, CryptoErrorCode.UNRECOVERABLE_KEY); } catch (KeyStoreException e) { throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION); } catch (NoSuchAlgorithmException e) { throw SeedException.wrap(e, CryptoErrorCode.ALGORITHM_CANNOT_BE_FOUND); } return new EncryptionServiceImpl(alias, pk, key); } EncryptionServiceFactory(KeyStore keyStore);  }
EncryptionServiceFactory { EncryptionService create(String alias, char[] password) { PublicKey pk = getPublicKey(alias); Key key; try { key = this.keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { throw SeedException.wrap(e, CryptoErrorCode.UNRECOVERABLE_KEY); } catch (KeyStoreException e) { throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION); } catch (NoSuchAlgorithmException e) { throw SeedException.wrap(e, CryptoErrorCode.ALGORITHM_CANNOT_BE_FOUND); } return new EncryptionServiceImpl(alias, pk, key); } EncryptionServiceFactory(KeyStore keyStore);   }