@Test public void emptyEmailShouldBeValidBecauseItIsNotBusy() { EditUserProfileDto editedUserProfile = new EditUserProfileDto(); editedUserProfile.setEmail(null); boolean isValid = validator.isValid(editedUserProfile, validatorContext); assertTrue(isValid, "Empty email should be valid, becuase it isn't busy."); }
@Test public void changedEmailShouldBeValidIfItIsNotBusy() { EditUserProfileDto editedUserProfile = new EditUserProfileDto(); editedUserProfile.setEmail("*****@*****.**"); boolean isValid = validator.isValid(editedUserProfile, validatorContext); assertTrue(isValid, "New email isn't taken, so it must be valid."); }
@Test public void notChangedEmailShouldBeValid() { EditUserProfileDto editedUserProfile = new EditUserProfileDto(); editedUserProfile.setEmail(userEmail); boolean isValid = validator.isValid(editedUserProfile, validatorContext); assertTrue(isValid, "Email of current user isn't valid."); }
@Test public void changedEmailShouldNotBeValidIfItIsBusy() { when(userDao.getByEmail(anyString())) .thenReturn(new JCUser("*****@*****.**", "email", "password")); EditUserProfileDto editedUserProfile = new EditUserProfileDto(); editedUserProfile.setEmail("*****@*****.**"); when(validatorContext.buildConstraintViolationWithTemplate(null)).thenReturn(violationBuilder); when(violationBuilder.addNode(anyString())).thenReturn(nodeBuilderDefinedContext); boolean isValid = validator.isValid(editedUserProfile, validatorContext); assertFalse(isValid, "New email is taken, so it must be invalid."); }