### Question:
KeystoreManager { public void addKeyPair(File keyStore, String storeType, char[] storePw, PrivateKey privKey, Certificate[] certChain, String alias) throws KeyStoreException { enforcePasswordComplexity(storePw, "invalidPassword"); KeyStore ks = openKeyStore(keyStore, storeType, storePw); ks.setKeyEntry(alias, privKey, storePw, certChain); saveKeyStore(ks, keyStore, storePw); }  void copyCert(final File keyStore, final File trustStore, final String alias, final String masterPassword); KeyStore openKeyStore(File source, String storeType, char[] pw); void saveKeyStore(KeyStore keyStore, File dest, char[] pw); void addKeyPair(File keyStore, String storeType, char[] storePw, PrivateKey privKey, Certificate[] certChain, String alias); void addKeyPair(File keyStore, String storeType, char[] storePw, PrivateKey privKey, char[] keyPw, Certificate[] certChain,
            String alias); void changeKeyStorePassword(File keyStore, String storeType, char[] oldPw, char[] newPw); void changeKeyStorePassword(File keyStore, String storeType, char[] oldPw, char[] newPw, boolean changeKeyPasswords); void changeKeyPassword(File keyStore, String storeType, char[] storePw, String alias, char[] oldKeyPw, char[] newKeyPw); PrivateKey readPlainPKCS8PrivateKey(File keyFile); PrivateKey readPlainPKCS8PrivateKey(InputStream is, String algo); Collection<? extends Certificate> readPemCertificateChain(File pemFile); static String getDASCertDN(final RepositoryConfig cfg); static String getInstanceCertDN(final RepositoryConfig cfg); static final String CERTIFICATE_ALIAS; static final String INSTANCE_SECURE_ADMIN_ALIAS; static final String DEFAULT_MASTER_PASSWORD; }### Answer:
@Test(expected = IllegalArgumentException.class) public void testAddKeyPairBadStorePw() throws KeyStoreException { manager.addKeyPair(null, "JKS", null, null, null, "nullTest"); }
@Test(expected = IllegalArgumentException.class) public void testAddKeyPairBadKeyPw() throws KeyStoreException { manager.addKeyPair(null, "JKS", "min6chars".toCharArray(), null, null, null, "nullTest"); }
@Test public void testAddKeyPair() throws CertificateException, IOException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException { String alias = "test2"; File f = copySampleKeyStore(storePw); PrivateKey privKey = manager.readPlainPKCS8PrivateKey( this.getClass().getResourceAsStream("privatekey.key"), "RSA"); Collection<? extends Certificate> certificates = CertificateFactory.getInstance("X.509") .generateCertificates(this.getClass().getResourceAsStream("certificate.pem")); manager.addKeyPair(f, "JKS", storePw, privKey, certificates.toArray(new Certificate[1]), alias); KeyStore ks = manager.openKeyStore(f, "JKS", storePw); assertTrue(ks.aliases().hasMoreElements()); assertTrue(ks.containsAlias(alias)); assertNotNull(ks.getKey(alias, storePw)); f.delete(); }