@Test public void testFindPasswordResetCount() throws Exception { final String email = "svd@163.com"; final String operatingIp = "ip"; final Date currentTime = new Date(); final Date startDate = new Date(currentTime.getTime() - 24L * 60 * 60 * 1000L); UserPasswordResetRepository userPasswordResetRepository = mock(UserPasswordResetRepository.class); when(userPasswordResetRepository .findNotExpiredByEmail(eq(email), eq(operatingIp), eq(startDate), eq(currentTime))) .thenReturn(null, Arrays.asList(new UserPasswordReset(), new UserPasswordReset())); UserServiceFacadeImpl service = new UserServiceFacadeImpl(); service.setUserPasswordResetRepository(userPasswordResetRepository); int count = service.findPasswordResetCount(email, operatingIp, currentTime); assertThat(count, equalTo(0)); count = service.findPasswordResetCount(email, operatingIp, currentTime); assertThat(count, equalTo(2)); verify(userPasswordResetRepository, times(2)).findNotExpiredByEmail(eq(email), eq(operatingIp), eq(startDate), eq(currentTime)); }
@Override public int findPasswordResetCount(String email, String ip, Date currentDate) { hasLength(email); hasLength(ip); notNull(currentDate); Date startDate = DateUtils.addDays(currentDate, -1); List<UserPasswordReset> resets = userPasswordResetRepository.findNotExpiredByEmail(email, ip, startDate, currentDate); if (isEmpty(resets)) { return 0; } return resets.size(); }
UserServiceFacadeImpl implements UserServiceFacade { @Override public int findPasswordResetCount(String email, String ip, Date currentDate) { hasLength(email); hasLength(ip); notNull(currentDate); Date startDate = DateUtils.addDays(currentDate, -1); List<UserPasswordReset> resets = userPasswordResetRepository.findNotExpiredByEmail(email, ip, startDate, currentDate); if (isEmpty(resets)) { return 0; } return resets.size(); } }
UserServiceFacadeImpl implements UserServiceFacade { @Override public int findPasswordResetCount(String email, String ip, Date currentDate) { hasLength(email); hasLength(ip); notNull(currentDate); Date startDate = DateUtils.addDays(currentDate, -1); List<UserPasswordReset> resets = userPasswordResetRepository.findNotExpiredByEmail(email, ip, startDate, currentDate); if (isEmpty(resets)) { return 0; } return resets.size(); }  }
UserServiceFacadeImpl implements UserServiceFacade { @Override public int findPasswordResetCount(String email, String ip, Date currentDate) { hasLength(email); hasLength(ip); notNull(currentDate); Date startDate = DateUtils.addDays(currentDate, -1); List<UserPasswordReset> resets = userPasswordResetRepository.findNotExpiredByEmail(email, ip, startDate, currentDate); if (isEmpty(resets)) { return 0; } return resets.size(); }  @Override UserAccount currentUser(); @Override UserEntry currentDetailUser(); @Override boolean isWithdrawPasswordSet(); @Override boolean isWithdrawPasswordMatched(String withdrawPassword); @Override boolean canAuthWithNewPassword(String username, String newPassword); @Override UserPasswordReset getToken(String token); PortfolioEntry obtainPortfolioForUser(); @Override boolean matchPreviousPassword(String previousPassword); @Override void editDetails(String username, String email, String cellPhoneNumber, String firstName, String lastName); @Override void editAdminDetails(String username,
                                 String email,
                                 Identifier identifier,
                                 String cellPhoneNumber,
                                 String firstName,
                                 String lastName,
                                 List<String> roles); @Override void updateNotificationSettings(boolean logonAlert, boolean withdrawMoneyAlert, boolean withdrawItemAlert, boolean executedAlert); @Override void changePassword(String previousPassword,
                               String newPassword,
                               String confirmedNewPassword,
                               String operatingIp,
                               Date changedTime); @Override boolean createWithdrawPassword(String withdrawPassword, String confirmedWithdrawPassword, String operatingIp, Date changedTime); @Override boolean matchPreviousWithdrawPassword(String previousPassword); boolean generateForgetPasswordToken(String email, String operatingIp, Date currentTime); @Override UserAccount resetPasswordWithToken(String token,
                                              String password,
                                              String confirmedPassword,
                                              String operatingIp,
                                              Date resetTime); @Override void changeWithdrawPassword(String previousPassword,
                                       String withdrawPassword,
                                       String confirmedWithdrawPassword,
                                       String operatingIp,
                                       Date changedTime); @Override UserEntry findByEmail(String email); @Override int findPasswordResetCount(String email, String ip, Date currentDate); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserService(UserService userService); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioQueryRepository(PortfolioQueryRepository portfolioQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @Autowired void setEmailSender(ForgetPasswordEmailSender emailSender); }
UserServiceFacadeImpl implements UserServiceFacade { @Override public int findPasswordResetCount(String email, String ip, Date currentDate) { hasLength(email); hasLength(ip); notNull(currentDate); Date startDate = DateUtils.addDays(currentDate, -1); List<UserPasswordReset> resets = userPasswordResetRepository.findNotExpiredByEmail(email, ip, startDate, currentDate); if (isEmpty(resets)) { return 0; } return resets.size(); }  @Override UserAccount currentUser(); @Override UserEntry currentDetailUser(); @Override boolean isWithdrawPasswordSet(); @Override boolean isWithdrawPasswordMatched(String withdrawPassword); @Override boolean canAuthWithNewPassword(String username, String newPassword); @Override UserPasswordReset getToken(String token); PortfolioEntry obtainPortfolioForUser(); @Override boolean matchPreviousPassword(String previousPassword); @Override void editDetails(String username, String email, String cellPhoneNumber, String firstName, String lastName); @Override void editAdminDetails(String username,
                                 String email,
                                 Identifier identifier,
                                 String cellPhoneNumber,
                                 String firstName,
                                 String lastName,
                                 List<String> roles); @Override void updateNotificationSettings(boolean logonAlert, boolean withdrawMoneyAlert, boolean withdrawItemAlert, boolean executedAlert); @Override void changePassword(String previousPassword,
                               String newPassword,
                               String confirmedNewPassword,
                               String operatingIp,
                               Date changedTime); @Override boolean createWithdrawPassword(String withdrawPassword, String confirmedWithdrawPassword, String operatingIp, Date changedTime); @Override boolean matchPreviousWithdrawPassword(String previousPassword); boolean generateForgetPasswordToken(String email, String operatingIp, Date currentTime); @Override UserAccount resetPasswordWithToken(String token,
                                              String password,
                                              String confirmedPassword,
                                              String operatingIp,
                                              Date resetTime); @Override void changeWithdrawPassword(String previousPassword,
                                       String withdrawPassword,
                                       String confirmedWithdrawPassword,
                                       String operatingIp,
                                       Date changedTime); @Override UserEntry findByEmail(String email); @Override int findPasswordResetCount(String email, String ip, Date currentDate); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserService(UserService userService); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioQueryRepository(PortfolioQueryRepository portfolioQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @Autowired void setEmailSender(ForgetPasswordEmailSender emailSender);  }