/**
  * We create here two account with the same email address. We expect here an
  * AccountCreationException with an embedded message about the duplicate email address.
  *
  * @throws AccountManagerException is thrown in case of account issues.
  * @throws PasswordCreationException is thrown in case of password creation issues.
  * @throws PasswordActivationException is thrown in case of password activation issues.
  */
 @Test(expected = EJBException.class)
 public void testCreateAccountDuplicateEmail()
     throws AccountManagerException, PasswordCreationException, PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
   // now we expect an error...
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
 }
 @Test
 public void testCreateAccount()
     throws AccountManagerException, PasswordCreationException, PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
 }
 @Test
 public void testAuthenticateWrongPassword()
     throws AccountManagerException, PasswordCreationException, PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
   assertFalse(
       passwordStoreClient.authenticate(
           EMAIL_ADDRESS, new Password(VALID_PASSWORD.getPassword() + "Wrong!")));
 }
 @Test(expected = PasswordChangeException.class)
 public void testChangePasswordTooWeakPassword()
     throws AccountManagerException, PasswordChangeException, PasswordCreationException,
         PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
   assertTrue(passwordStoreClient.authenticate(EMAIL_ADDRESS, VALID_PASSWORD));
   accountManager.changePassword(EMAIL_ADDRESS, VALID_PASSWORD, TOO_WEAK_PASSWORD);
 }
 @Test
 public void testResetPassword()
     throws AccountManagerException, PasswordResetException, PasswordCreationException,
         PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
   assertTrue(passwordStoreClient.authenticate(EMAIL_ADDRESS, VALID_PASSWORD));
   Password newPassword = accountManager.resetPassword(EMAIL_ADDRESS);
   assertTrue(passwordStoreClient.authenticate(EMAIL_ADDRESS, newPassword));
 }
 @Test
 public void testChangePassword()
     throws AccountManagerException, PasswordChangeException, PasswordCreationException,
         PasswordActivationException {
   String activationKey = accountManager.createPassword(EMAIL_ADDRESS, VALID_PASSWORD);
   accountManager.activatePassword(EMAIL_ADDRESS, activationKey);
   accountManager.createAccount(EMAIL_ADDRESS, EMAIL_ADDRESS.getAddress(), "engineer");
   assertTrue(passwordStoreClient.authenticate(EMAIL_ADDRESS, VALID_PASSWORD));
   String newPassword = VALID_PASSWORD.getPassword() + "New!";
   assertTrue(
       accountManager.changePassword(EMAIL_ADDRESS, VALID_PASSWORD, new Password(newPassword)));
   assertTrue(passwordStoreClient.authenticate(EMAIL_ADDRESS, new Password(newPassword)));
 }