EmailExistsValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String email = (String) value; if (email == null || email.length() == 0) { return; } Long userUsingUsername = (Long) em.createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.email = :email") .setParameter("email", email).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("A user with this email address is already registered.")); } }  @Override void validate(FacesContext context, UIComponent component, Object value); void setEntityManager(EntityManager em);  }
@Test public void validate_stopValidationIfNoUsernameIsPassed() { emailExValidator.validate(null, null, ""); assertTrue(true); }