@Test public void testAddCarsFail() { try { List<Car> cars = getValidCars(); cars.get(0).setLicensePlate("xxx123"); cars.get(1).setSeatCount(0); cars.get(1).setManufacturer("XXX"); garageService.addCars(cars); } catch (CarException e) { assertThat(e.getClass().getName(), is(CarException.class.getName())); assertThat(e.getMessage(), is(String.format(CarError.LICENSEPLATE_ERROR.msg(), "xxx123"))); } }
@Override public Result addCars(List<Car> cars) { Preconditions.checkNotNull(cars, "car should not be null"); Result result = FluentValidator.checkAll() .configure(springApplicationContextRegistry) .onEach(cars) .doValidate(new DefaultValidateCallback() { @Override public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) { throw new CarException(errors.get(0).getErrorMsg()); } @Override public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception { throw new CarException(e); } }) .result(toSimple()); return result; }
GarageServiceImpl implements GarageService { @Override public Result addCars(List<Car> cars) { Preconditions.checkNotNull(cars, "car should not be null"); Result result = FluentValidator.checkAll() .configure(springApplicationContextRegistry) .onEach(cars) .doValidate(new DefaultValidateCallback() { @Override public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) { throw new CarException(errors.get(0).getErrorMsg()); } @Override public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception { throw new CarException(e); } }) .result(toSimple()); return result; } }
GarageServiceImpl implements GarageService { @Override public Result addCars(List<Car> cars) { Preconditions.checkNotNull(cars, "car should not be null"); Result result = FluentValidator.checkAll() .configure(springApplicationContextRegistry) .onEach(cars) .doValidate(new DefaultValidateCallback() { @Override public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) { throw new CarException(errors.get(0).getErrorMsg()); } @Override public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception { throw new CarException(e); } }) .result(toSimple()); return result; }  }
GarageServiceImpl implements GarageService { @Override public Result addCars(List<Car> cars) { Preconditions.checkNotNull(cars, "car should not be null"); Result result = FluentValidator.checkAll() .configure(springApplicationContextRegistry) .onEach(cars) .doValidate(new DefaultValidateCallback() { @Override public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) { throw new CarException(errors.get(0).getErrorMsg()); } @Override public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception { throw new CarException(e); } }) .result(toSimple()); return result; }  @Override Result addCars(List<Car> cars); @Override Result addCarsThrowException(List<Car> cars); @Override Result addCar(Car car); @Override ComplexResult buildGarage(Garage garage); }
GarageServiceImpl implements GarageService { @Override public Result addCars(List<Car> cars) { Preconditions.checkNotNull(cars, "car should not be null"); Result result = FluentValidator.checkAll() .configure(springApplicationContextRegistry) .onEach(cars) .doValidate(new DefaultValidateCallback() { @Override public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) { throw new CarException(errors.get(0).getErrorMsg()); } @Override public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception { throw new CarException(e); } }) .result(toSimple()); return result; }  @Override Result addCars(List<Car> cars); @Override Result addCarsThrowException(List<Car> cars); @Override Result addCar(Car car); @Override ComplexResult buildGarage(Garage garage);  }