1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Car car = new Car("Morris", "DD-AB-123", 2 ); Set<ConstraintViolation<Car>> constraintViolations = validator.validate(car); assertEquals(0, constraintViolations.size());
constraintViolations = validator.validate(car, CarChecks.class); assertEquals(1, constraintViolations.size()); assertEquals( "The car has to pass the vehicle inspection first", constraintViolations.iterator().next().getMessage() );
car.setPassedVehicleInspection(true ); assertEquals(0, validator.validate(car, CarChecks.class).size());
Driver john = new Driver("John Doe" ); john.setAge(18 ); car.setDriver(john); constraintViolations = validator.validate(car, DriverChecks.class); assertEquals(1, constraintViolations.size()); assertEquals( "You first have to pass the driving test", constraintViolations.iterator().next().getMessage() );
john.passedDrivingTest(true ); assertEquals(0, validator.validate(car, DriverChecks.class).size());
assertEquals( 0, validator.validate( car, Default.class, CarChecks.class, DriverChecks.class ).size() );
|