Search in sources :

Example 1 with Car

use of org.mapstruct.ap.test.complex.source.Car in project mapstruct by mapstruct.

the class CarMapperTest method shouldReverseMapIterable.

@ProcessorTest
public void shouldReverseMapIterable() {
    // given
    CarDto car1 = new CarDto("Morris", 2, "1980", new PersonDto("Bob"), new ArrayList<>());
    CarDto car2 = new CarDto("Railton", 4, "1934", new PersonDto("Bill"), new ArrayList<>());
    // when
    List<Car> cars = CarMapper.INSTANCE.carDtosToCars(Arrays.asList(car1, car2));
    // then
    assertThat(cars).isNotNull();
    assertThat(cars).hasSize(2);
    assertThat(cars.get(0).getMake()).isEqualTo("Morris");
    assertThat(cars.get(0).getNumberOfSeats()).isEqualTo(2);
    assertThat(cars.get(0).getManufacturingDate()).isEqualTo(new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime());
    assertThat(cars.get(0).getDriver().getName()).isEqualTo("Bob");
    assertThat(cars.get(1).getMake()).isEqualTo("Railton");
    assertThat(cars.get(1).getNumberOfSeats()).isEqualTo(4);
    assertThat(cars.get(1).getManufacturingDate()).isEqualTo(new GregorianCalendar(1934, Calendar.JANUARY, 1).getTime());
    assertThat(cars.get(1).getDriver().getName()).isEqualTo("Bill");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) PersonDto(org.mapstruct.ap.test.complex._target.PersonDto) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 2 with Car

use of org.mapstruct.ap.test.complex.source.Car in project mapstruct by mapstruct.

the class CarMapperTest method shouldConsiderCustomMappingForReverseMapping.

@ProcessorTest
public void shouldConsiderCustomMappingForReverseMapping() {
    // given
    CarDto carDto = new CarDto("Morris", 2, "1980", new PersonDto("Bob"), new ArrayList<>());
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getNumberOfSeats()).isEqualTo(carDto.getSeatCount());
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) PersonDto(org.mapstruct.ap.test.complex._target.PersonDto) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 3 with Car

use of org.mapstruct.ap.test.complex.source.Car in project mapstruct by mapstruct.

the class CarMapperTest method shouldMapReferenceAttribute.

@ProcessorTest
public void shouldMapReferenceAttribute() {
    // given
    Car car = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), new ArrayList<>());
    // when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getDriver()).isNotNull();
    assertThat(carDto.getDriver().getName()).isEqualTo("Bob");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) Person(org.mapstruct.ap.test.complex.source.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 4 with Car

use of org.mapstruct.ap.test.complex.source.Car in project mapstruct by mapstruct.

the class CarMapperTest method shouldReverseMapReferenceAttribute.

@ProcessorTest
public void shouldReverseMapReferenceAttribute() {
    // given
    CarDto carDto = new CarDto("Morris", 2, "1980", new PersonDto("Bob"), new ArrayList<>());
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getDriver()).isNotNull();
    assertThat(car.getDriver().getName()).isEqualTo("Bob");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) PersonDto(org.mapstruct.ap.test.complex._target.PersonDto) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with Car

use of org.mapstruct.ap.test.complex.source.Car in project mapstruct by mapstruct.

the class CarMapperTest method shouldApplyConverterForReverseMapping.

@ProcessorTest
public void shouldApplyConverterForReverseMapping() {
    // given
    CarDto carDto = new CarDto("Morris", 2, "1980", new PersonDto("Bob"), new ArrayList<>());
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getManufacturingDate()).isEqualTo(new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime());
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) PersonDto(org.mapstruct.ap.test.complex._target.PersonDto) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)13 GregorianCalendar (java.util.GregorianCalendar)8 Person (org.mapstruct.ap.test.complex.source.Person)6 PersonDto (org.mapstruct.ap.test.complex._target.PersonDto)5