### Question:
UserAgentImpl extends PassphraseAgentImpl implements UserAgent { public static UserAgentImpl createUserAgent(String passphrase) throws CryptoException, AgentOperationFailedException { byte[] salt = CryptoTools.generateSalt(); return new UserAgentImpl(CryptoTools.generateKeyPair(), passphrase, salt); } protected  UserAgentImpl(KeyPair pair, String passphrase, byte[] salt); protected  UserAgentImpl(PublicKey pubKey, byte[] encryptedPrivate, byte[] salt); @Override String getLoginName(); @Override boolean hasLoginName(); @Override void setLoginName(String loginName); @Override void setEmail(String email); @Override String toXmlString(); static UserAgentImpl createFromXml(String xml); static UserAgentImpl createUserAgent(String passphrase); static UserAgentImpl createFromXml(Element root); @Override void receiveMessage(Message message, AgentContext context); @Override void notifyUnregister(); @Override String getEmail(); @Override boolean hasEmail();  }### Answer:
@Test public void testUnlocking() throws NoSuchAlgorithmException, CryptoException, AgentAccessDeniedException, InternalSecurityException, AgentLockedException, AgentOperationFailedException { String passphrase = "A passphrase to unlock"; UserAgentImpl a = UserAgentImpl.createUserAgent(passphrase); try { a.decryptSymmetricKey(null); fail("AgentLockedException should have been thrown"); } catch (AgentLockedException e) { } catch (SerializationException e) { fail("SecurityException should have been thrown"); e.printStackTrace(); } try { a.unlock("bad passphrase"); fail("SecurityException should have been thrown"); } catch (AgentAccessDeniedException e) { } try { a.decryptSymmetricKey(null); fail("AgentLockedException should have been thrown"); } catch (AgentLockedException e) { } catch (SerializationException e) { fail("AgentLockedException should have been thrown"); e.printStackTrace(); } a.unlock(passphrase); try { a.decryptSymmetricKey(null); } catch (IllegalArgumentException e) { } catch (SerializationException e) { fail("Illegal argument exception should have been thrown"); e.printStackTrace(); } }
@Test public void testPassphraseChange() throws NoSuchAlgorithmException, InternalSecurityException, CryptoException, AgentAccessDeniedException, AgentLockedException, AgentOperationFailedException { String passphrase = "a passphrase"; UserAgentImpl a = UserAgentImpl.createUserAgent(passphrase); String sndPass = "ein anderes Passphrase"; try { a.changePassphrase(sndPass); fail("AgentLockedException expected"); } catch (AgentLockedException e) { } a.unlock(passphrase); a.changePassphrase(sndPass); a.lockPrivateKey(); try { a.unlock(passphrase); fail("AgentAccessDeniedException expected"); } catch (AgentAccessDeniedException e) { } a.unlock(sndPass); }