@Test(expected = IllegalArgumentException.class) public void testCreateEmailToken_Throws_Exception_When_Email_Has_Whitespaces_Only() throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { sut.createEmailToken("username", " "); }
@Override public String createEmailToken(String username, String emailAddress) throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { String emailLinkPlaceHolder = "?token=%s"; if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username is required."); } if (!StringUtils.hasText(emailAddress)) { throw new IllegalArgumentException("Email Address is required."); } Patient patient = patientRepository.findByUsername(username); String patientEmailAddress = patient.getEmail(); if (!patientEmailAddress.equalsIgnoreCase(emailAddress)) { String message = String.format( "Email address %s doesn't exist for username %s.", emailAddress, username); logger.info("message"); throw new EmailAddressNotExistException(message); } EmailToken accountVerificationToken = new EmailToken(); accountVerificationToken .setExpireInHours(accountVerificationTokenExpireInHours); accountVerificationToken.setRequestDateTime(new Date()); String token = tokenGenerator.generateToken(); accountVerificationToken.setToken(token); accountVerificationToken.setUsername(username); accountVerificationToken.setIsTokenUsed(false); accountVerificationToken.setTokenType(TokenType.ACCOUNT_VERIFICATION); emailTokenRepository.save(accountVerificationToken); String link = String.format(emailLinkPlaceHolder, token); return link; }
AccountServiceImpl implements AccountService { @Override public String createEmailToken(String username, String emailAddress) throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { String emailLinkPlaceHolder = "?token=%s"; if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username is required."); } if (!StringUtils.hasText(emailAddress)) { throw new IllegalArgumentException("Email Address is required."); } Patient patient = patientRepository.findByUsername(username); String patientEmailAddress = patient.getEmail(); if (!patientEmailAddress.equalsIgnoreCase(emailAddress)) { String message = String.format( "Email address %s doesn't exist for username %s.", emailAddress, username); logger.info("message"); throw new EmailAddressNotExistException(message); } EmailToken accountVerificationToken = new EmailToken(); accountVerificationToken .setExpireInHours(accountVerificationTokenExpireInHours); accountVerificationToken.setRequestDateTime(new Date()); String token = tokenGenerator.generateToken(); accountVerificationToken.setToken(token); accountVerificationToken.setUsername(username); accountVerificationToken.setIsTokenUsed(false); accountVerificationToken.setTokenType(TokenType.ACCOUNT_VERIFICATION); emailTokenRepository.save(accountVerificationToken); String link = String.format(emailLinkPlaceHolder, token); return link; } }
AccountServiceImpl implements AccountService { @Override public String createEmailToken(String username, String emailAddress) throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { String emailLinkPlaceHolder = "?token=%s"; if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username is required."); } if (!StringUtils.hasText(emailAddress)) { throw new IllegalArgumentException("Email Address is required."); } Patient patient = patientRepository.findByUsername(username); String patientEmailAddress = patient.getEmail(); if (!patientEmailAddress.equalsIgnoreCase(emailAddress)) { String message = String.format( "Email address %s doesn't exist for username %s.", emailAddress, username); logger.info("message"); throw new EmailAddressNotExistException(message); } EmailToken accountVerificationToken = new EmailToken(); accountVerificationToken .setExpireInHours(accountVerificationTokenExpireInHours); accountVerificationToken.setRequestDateTime(new Date()); String token = tokenGenerator.generateToken(); accountVerificationToken.setToken(token); accountVerificationToken.setUsername(username); accountVerificationToken.setIsTokenUsed(false); accountVerificationToken.setTokenType(TokenType.ACCOUNT_VERIFICATION); emailTokenRepository.save(accountVerificationToken); String link = String.format(emailLinkPlaceHolder, token); return link; } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); }
AccountServiceImpl implements AccountService { @Override public String createEmailToken(String username, String emailAddress) throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { String emailLinkPlaceHolder = "?token=%s"; if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username is required."); } if (!StringUtils.hasText(emailAddress)) { throw new IllegalArgumentException("Email Address is required."); } Patient patient = patientRepository.findByUsername(username); String patientEmailAddress = patient.getEmail(); if (!patientEmailAddress.equalsIgnoreCase(emailAddress)) { String message = String.format( "Email address %s doesn't exist for username %s.", emailAddress, username); logger.info("message"); throw new EmailAddressNotExistException(message); } EmailToken accountVerificationToken = new EmailToken(); accountVerificationToken .setExpireInHours(accountVerificationTokenExpireInHours); accountVerificationToken.setRequestDateTime(new Date()); String token = tokenGenerator.generateToken(); accountVerificationToken.setToken(token); accountVerificationToken.setUsername(username); accountVerificationToken.setIsTokenUsed(false); accountVerificationToken.setTokenType(TokenType.ACCOUNT_VERIFICATION); emailTokenRepository.save(accountVerificationToken); String link = String.format(emailLinkPlaceHolder, token); return link; } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); @Override @Transactional void signup(SignupDto signupDto, String linkUrl); @Override String createEmailToken(String username, String emailAddress); @Override Users findUserByUsername(String username); @Override String recoverUsername(String firstName, String lastName,
			String birthDay, String email); }
AccountServiceImpl implements AccountService { @Override public String createEmailToken(String username, String emailAddress) throws UsernameNotExistException, EmailAddressNotExistException, MessagingException { String emailLinkPlaceHolder = "?token=%s"; if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username is required."); } if (!StringUtils.hasText(emailAddress)) { throw new IllegalArgumentException("Email Address is required."); } Patient patient = patientRepository.findByUsername(username); String patientEmailAddress = patient.getEmail(); if (!patientEmailAddress.equalsIgnoreCase(emailAddress)) { String message = String.format( "Email address %s doesn't exist for username %s.", emailAddress, username); logger.info("message"); throw new EmailAddressNotExistException(message); } EmailToken accountVerificationToken = new EmailToken(); accountVerificationToken .setExpireInHours(accountVerificationTokenExpireInHours); accountVerificationToken.setRequestDateTime(new Date()); String token = tokenGenerator.generateToken(); accountVerificationToken.setToken(token); accountVerificationToken.setUsername(username); accountVerificationToken.setIsTokenUsed(false); accountVerificationToken.setTokenType(TokenType.ACCOUNT_VERIFICATION); emailTokenRepository.save(accountVerificationToken); String link = String.format(emailLinkPlaceHolder, token); return link; } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); @Override @Transactional void signup(SignupDto signupDto, String linkUrl); @Override String createEmailToken(String username, String emailAddress); @Override Users findUserByUsername(String username); @Override String recoverUsername(String firstName, String lastName,
			String birthDay, String email);  }