@Test public void sendResetPassword() { Account account = service.createViaEmail("myname", "foo@gmail.com", "pwd123", lc); Mockito.reset(mockMailAgent); service.sendResetPassword("myname", "foo@gmail.com", lc); verify(mockMailAgent).sendResetPassword(eq(lc), eq(account), Mockito.matches("[a-z\\-0-9]{36}")); assertTrue(accountDao.listOnceTokens() .stream() .anyMatch(token -> token.getTokenType() == AccountOnceToken.Type.FORGET_PASSWORD)); }
@Override public void sendResetPassword(String username, String email, Locale locale) { logger.info("begin reset password: {}, {}", username, email); accountDao.findByUsername(username) .filter(account -> account.getEmail().equals(email)) .ifPresent(account -> { AccountOnceToken token = accountDao.createOnceToken(account, AccountOnceToken.Type.FORGET_PASSWORD, Instant.now(clock)); mailAgent.sendResetPassword(locale, account, token.getToken()); }); }
AccountServiceImpl implements AccountService { @Override public void sendResetPassword(String username, String email, Locale locale) { logger.info("begin reset password: {}, {}", username, email); accountDao.findByUsername(username) .filter(account -> account.getEmail().equals(email)) .ifPresent(account -> { AccountOnceToken token = accountDao.createOnceToken(account, AccountOnceToken.Type.FORGET_PASSWORD, Instant.now(clock)); mailAgent.sendResetPassword(locale, account, token.getToken()); }); } }
AccountServiceImpl implements AccountService { @Override public void sendResetPassword(String username, String email, Locale locale) { logger.info("begin reset password: {}, {}", username, email); accountDao.findByUsername(username) .filter(account -> account.getEmail().equals(email)) .ifPresent(account -> { AccountOnceToken token = accountDao.createOnceToken(account, AccountOnceToken.Type.FORGET_PASSWORD, Instant.now(clock)); mailAgent.sendResetPassword(locale, account, token.getToken()); }); }  }
AccountServiceImpl implements AccountService { @Override public void sendResetPassword(String username, String email, Locale locale) { logger.info("begin reset password: {}, {}", username, email); accountDao.findByUsername(username) .filter(account -> account.getEmail().equals(email)) .ifPresent(account -> { AccountOnceToken token = accountDao.createOnceToken(account, AccountOnceToken.Type.FORGET_PASSWORD, Instant.now(clock)); mailAgent.sendResetPassword(locale, account, token.getToken()); }); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken); }
AccountServiceImpl implements AccountService { @Override public void sendResetPassword(String username, String email, Locale locale) { logger.info("begin reset password: {}, {}", username, email); accountDao.findByUsername(username) .filter(account -> account.getEmail().equals(email)) .ifPresent(account -> { AccountOnceToken token = accountDao.createOnceToken(account, AccountOnceToken.Type.FORGET_PASSWORD, Instant.now(clock)); mailAgent.sendResetPassword(locale, account, token.getToken()); }); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken);  }