GarageServiceImpl2 implements GarageService2 { @Override public Garage buildGarage(@FluentValid Garage garage) { System.out.println(garage); return garage; }  @Override List<Car> addCars(@FluentValid(NotEmptyValidator.class) List<Car> cars); @Override List<Car> addCarsThrowException(@FluentValid List<Car> cars); @Override Car addCar(@FluentValid Car car); @Override Garage buildGarage(@FluentValid Garage garage);  }
@Test public void testBuildGarageInvalidOwner() { try { Garage garage = getValidGarage(); garage.getOwner().setId(0); garage.getOwner().setName("hh"); garageService.buildGarage(garage); } catch (CarException e) { System.out.println(e.getMessage()); assertThat(e.getClass().getName(), is(CarException.class.getName())); } }
@Test public void testBuildGarageCarNumExceed() { try { Garage garage = getValidGarage(); List<Car> cars = Lists.newArrayList(); for (int i = 0; i < 100; i++) { cars.add(new Car("BMW", "LA1234", 5)); } garage.setCarList(cars); garageService.buildGarage(garage); } catch (CarException e) { assertThat(e.getClass().getName(), is(CarException.class.getName())); assertThat(e.getMessage(), is(MessageSupport.getText("car.size.exceed", 50))); } }
@Test public void testBuildGarageInvalidCar() { try { Garage garage = getValidGarage(); garage.getCarList().get(0).setLicensePlate("xxx"); garageService.buildGarage(garage); } catch (CarException e) { assertThat(e.getClass().getName(), is(CarException.class.getName())); assertThat(e.getMessage(), is("License is not valid, invalid value=xxx")); } }
@Test public void testBuildGarage() { Garage garage = getValidGarage(); garageService.buildGarage(garage); }
@Test public void testBuildGarageInvalidName() { try { Garage garage = getValidGarage(); garage.setName("abc"); garageService.buildGarage(garage); } catch (CarException e) { assertThat(e.getClass().getName(), is(CarException.class.getName())); assertThat(e.getMessage(), is("车库名称长度非法")); } }