@Test public void when_emailadress_found__onetimetoken_created_and_persisted() throws Exception { User user = new User(); user.emailAdress="user@test.com"; user.name="testuser"; when(mockedUserRepository.findByEmailAdress("user@test.com")).thenReturn(Optional.of(user)); serviceToTest.anonymousRequestToGetNewApiTokenForUserMailAdress("user@test.com"); assertEquals(FAKE_ONE_TIME_TOKEN,user.oneTimeToken); assertNotNull(user.oneTimeTokenDate); verify(mockedUserRepository).save(user); }
public void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail) { LOG.info("New api token requested for email address: {})",logSanitizer.sanitize(userEmail,50)); assertion.isValidEmailAddress(userEmail); Optional<User> found = userRepository.findByEmailAdress(userEmail); if (! found.isPresent()) { LOG.warn("Anonymous request to get new api token, but user unknown: {})",logSanitizer.sanitize(userEmail,50)); return; } User user = saveUserWithNewOneTimeToken(found); sendUserNewApiTokenRequested(userEmail, user); }
AnonymousUserRequestsNewApiTokenService { public void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail) { LOG.info("New api token requested for email address: {})",logSanitizer.sanitize(userEmail,50)); assertion.isValidEmailAddress(userEmail); Optional<User> found = userRepository.findByEmailAdress(userEmail); if (! found.isPresent()) { LOG.warn("Anonymous request to get new api token, but user unknown: {})",logSanitizer.sanitize(userEmail,50)); return; } User user = saveUserWithNewOneTimeToken(found); sendUserNewApiTokenRequested(userEmail, user); } }
AnonymousUserRequestsNewApiTokenService { public void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail) { LOG.info("New api token requested for email address: {})",logSanitizer.sanitize(userEmail,50)); assertion.isValidEmailAddress(userEmail); Optional<User> found = userRepository.findByEmailAdress(userEmail); if (! found.isPresent()) { LOG.warn("Anonymous request to get new api token, but user unknown: {})",logSanitizer.sanitize(userEmail,50)); return; } User user = saveUserWithNewOneTimeToken(found); sendUserNewApiTokenRequested(userEmail, user); }  }
AnonymousUserRequestsNewApiTokenService { public void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail) { LOG.info("New api token requested for email address: {})",logSanitizer.sanitize(userEmail,50)); assertion.isValidEmailAddress(userEmail); Optional<User> found = userRepository.findByEmailAdress(userEmail); if (! found.isPresent()) { LOG.warn("Anonymous request to get new api token, but user unknown: {})",logSanitizer.sanitize(userEmail,50)); return; } User user = saveUserWithNewOneTimeToken(found); sendUserNewApiTokenRequested(userEmail, user); }  void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail); }
AnonymousUserRequestsNewApiTokenService { public void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail) { LOG.info("New api token requested for email address: {})",logSanitizer.sanitize(userEmail,50)); assertion.isValidEmailAddress(userEmail); Optional<User> found = userRepository.findByEmailAdress(userEmail); if (! found.isPresent()) { LOG.warn("Anonymous request to get new api token, but user unknown: {})",logSanitizer.sanitize(userEmail,50)); return; } User user = saveUserWithNewOneTimeToken(found); sendUserNewApiTokenRequested(userEmail, user); }  void anonymousRequestToGetNewApiTokenForUserMailAdress(String userEmail);  }