PasswordResetServiceImpl implements PasswordResetService { @Override public Boolean isPasswordResetTokenExpired(String token) throws TokenNotExistException { if (!StringUtils.hasText(token)) { throw new IllegalArgumentException( "Password reset token is required."); } EmailToken passwordResetToken = findPasswordResetToken(token); Boolean isExpired = passwordResetToken.isTokenExpired(); return isExpired; } PasswordResetServiceImpl(Integer passwordResetTokenExpireInHours,
			UsersRepository usersRepository,
			PatientRepository patientRepository,
			StaffRepository staffRepository, TokenGenerator tokenGenerator,
			EmailTokenRepository passwordResetTokenRepository,
			EmailSender emailSender, PasswordEncoder passwordEncoder); @Override void createPasswordResetToken(String username, String emailAddress,
			String linkUrl); @Override Boolean isPasswordResetTokenExpired(String token); @Override void resetPassword(PasswordResetDto passwordResetDto, String linkUrl); @Override boolean changePassword(PasswordChangeDto passwordChangeDto);  }
@Test(expected = IllegalArgumentException.class) public void testIsPasswordResetTokenExpired_Throws_Exception_When_Token_Has_Whitespaces_Only() throws TokenNotExistException { sut.isPasswordResetTokenExpired(" "); }
@Test(expected = IllegalArgumentException.class) public void testIsPasswordResetTokenExpired_Throws_Exception_When_Token_Is_Null() throws TokenNotExistException { sut.isPasswordResetTokenExpired(null); }
@Test(expected = TokenNotExistException.class) public void testIsPasswordResetTokenExpired_Throws_Exception_When_PasswordToken_Not_Exist() throws TokenNotExistException { final String token = "TheToken"; when(passwordResetTokenRepository.findByToken(token)).thenReturn(null); sut.isPasswordResetTokenExpired(token); }
@Test public void testIsPasswordResetTokenExpired_Returns_True_Successfully() throws TokenNotExistException { final String token = "TheToken"; EmailToken passwordResetToken = mock(EmailToken.class); when(passwordResetToken.isTokenExpired()).thenReturn(true); when(passwordResetTokenRepository.findByToken(token)).thenReturn( passwordResetToken); Boolean result = sut.isPasswordResetTokenExpired(token); assertTrue(result); }
@Test public void testIsPasswordResetTokenExpired_Returns_False_Successfully() throws TokenNotExistException { final String token = "TheToken"; EmailToken passwordResetToken = mock(EmailToken.class); when(passwordResetToken.isTokenExpired()).thenReturn(false); when(passwordResetTokenRepository.findByToken(token)).thenReturn( passwordResetToken); Boolean result = sut.isPasswordResetTokenExpired(token); assertFalse(result); }