content: package org.agoncal.book.javaee7.chapter03;
  
  import org.junit.Test;
  
  import javax.validation.ConstraintViolation;
  import javax.validation.Validation;
  import javax.validation.Validator;
  import javax.validation.ValidatorFactory;
  import java.util.Set;
  
  import static org.junit.Assert.assertEquals;
  
  /**
   * @author Antonio Goncalves
   *         APress Book - Beginning Java EE 7 with Glassfish 4
   *         http://www.apress.com/
   *         http://www.antoniogoncalves.org
   *         --
   */
  public class AddressIT {
  
    // ======================================
    // =              Methods               =
    // ======================================
  
    @Test
    public void shouldRaiseConstraintViolationCauseInvalidZipCode() {
  
      ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
      Validator validator = vf.getValidator();
  
      Address address = new Address("233 Spring Street", "New York", "NY", "DummyZip", "USA");
  
      Set<ConstraintViolation<Address>> violations = validator.validate(address);
      assertEquals(1, violations.size());
  
      vf.close();
    }
  }