AccountVerificationServiceImpl implements
		AccountVerificationService { @Override public Boolean isAccountVerificationTokenExpired(String token) throws TokenNotExistException { if (!StringUtils.hasText(token)) { throw new IllegalArgumentException( "Account verification token is required."); } EmailToken accountVerificatioinToken = findToken(token); Boolean isExpired = accountVerificatioinToken.isTokenExpired(); return isExpired; } AccountVerificationServiceImpl(UsersRepository usersRepository,
			PatientRepository patientRepository,
			EmailTokenRepository emailTokenRepository, EmailSender emailSender); @Override Boolean isAccountVerificationTokenExpired(String token); @Override void enableAccount(AccountVerificationDto accountVerificationDto,
			String linkUrl);  }
@Test(expected = IllegalArgumentException.class) public void testIsEmailTokenExpired_Throws_Exception_When_Token_Has_Whitespaces_Only() throws TokenNotExistException { sut.isAccountVerificationTokenExpired(" "); }
@Test(expected = IllegalArgumentException.class) public void testIsEmailTokenExpired_Throws_Exception_When_Token_Is_Null() throws TokenNotExistException { sut.isAccountVerificationTokenExpired(null); }
@Test(expected = TokenNotExistException.class) public void testIsEmailTokenExpired_Throws_Exception_When_PasswordToken_Not_Exist() throws TokenNotExistException { final String token = "TheToken"; when(emailTokenRepository.findByToken(token)).thenReturn(null); sut.isAccountVerificationTokenExpired(token); }
@Test public void testIsEmailTokenExpired_Returns_True_Successfully() throws TokenNotExistException { final String token = "TheToken"; EmailToken passwordResetToken = mock(EmailToken.class); when(passwordResetToken.isTokenExpired()).thenReturn(true); when(emailTokenRepository.findByToken(token)).thenReturn( passwordResetToken); Boolean result = sut.isAccountVerificationTokenExpired(token); assertTrue(result); }
@Test public void testIsEmailTokenExpired_Returns_False_Successfully() throws TokenNotExistException { final String token = "TheToken"; EmailToken passwordResetToken = mock(EmailToken.class); when(passwordResetToken.isTokenExpired()).thenReturn(false); when(emailTokenRepository.findByToken(token)).thenReturn( passwordResetToken); Boolean result = sut.isAccountVerificationTokenExpired(token); assertFalse(result); }