Package org.hibernate.validator.referenceguide.chapter02.typeargument

Examples of org.hibernate.validator.referenceguide.chapter02.typeargument.Car


    assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() );
  }

  @Test
  public void validateListTypeArgumentConstraint() {
    Car car = new Car();
    car.addPart( "Wheel" );
    car.addPart( null );

    Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );

    assertEquals( 1, constraintViolations.size() );
    assertEquals(
View Full Code Here


    assertEquals( "parts[1]", constraintViolations.iterator().next().getPropertyPath().toString() );
  }

  @Test
  public void validateMapTypeArgumentConstraint() {
    Car car = new Car();
    car.setFuelConsumption( Car.FuelConsumption.HIGHWAY, 20 );

    Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );

    assertEquals( 1, constraintViolations.size() );
    assertEquals( "20 is outside the max fuel consumption.", constraintViolations.iterator().next().getMessage() );
View Full Code Here

    assertEquals( "20 is outside the max fuel consumption.", constraintViolations.iterator().next().getMessage() );
  }

  @Test
  public void validateOptionalTypeArgumentConstraint() {
    Car car = new Car();
    car.setTowingCapacity( 100 );

    Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );

    assertEquals( 1, constraintViolations.size() );
    assertEquals( "Not enough towing capacity.", constraintViolations.iterator().next().getMessage() );
View Full Code Here

    assertEquals( "towingCapacity", constraintViolations.iterator().next().getPropertyPath().toString() );
  }

  @Test
  public void validateCustomTypeArgumentConstraint() {
    Car car = new Car();
    car.setGearBox( new GearBox<>( new Gear.AcmeGear() ) );

    Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
    assertEquals( 1, constraintViolations.size() );
    assertEquals( "Gear is not providing enough torque.", constraintViolations.iterator().next().getMessage() );
    assertEquals( "gearBox", constraintViolations.iterator().next().getPropertyPath().toString() );
View Full Code Here

  @BeforeClass
  public static void setUpValidator() {
    ValidatorFactory factory = Validation.byProvider( HibernateValidator.class )
        .configure()
        .addValidatedValueHandler( new GearBoxUnwrapper() )
        .buildValidatorFactory();
    validator = factory.getValidator();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.validator.referenceguide.chapter02.typeargument.Car

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.