NotActivatedValidator implements ConstraintValidator<NotActivated, String> { @Override public boolean isValid(String email, ConstraintValidatorContext context) { final UserEntity user = userRepository.findByEmail(email.toLowerCase()); if (user == null || !user.isActivated()) { return true; } context.buildConstraintViolationWithTemplate("not_activated").addConstraintViolation(); return false; }  @Override void initialize(NotActivated constraintAnnotation); @Override boolean isValid(String email, ConstraintValidatorContext context);  }
@Test public void testIsValidNonExistingEmail() throws Exception { assertTrue(validator.isValid(NON_EXISTING_EMAIL, validatorContext)); }
@Test public void testIsValidExistingEmailNotActivated() throws Exception { assertTrue(validator.isValid(EXISTING_EMAIL_NOT_ACTIVATED, validatorContext)); }
@Test public void testIsValidExistingEmailActivated() throws Exception { assertFalse(validator.isValid(EXISTING_EMAIL_ACTIVATED, validatorContext)); }