Search in sources :

Example 6 with Car

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

the class CarMapperTest method shouldReverseMapIterableAttribute.

@ProcessorTest
public void shouldReverseMapIterableAttribute() {
    // given
    CarDto carDto = new CarDto("Morris", 2, "1980", new PersonDto("Bob"), Arrays.asList(new PersonDto("Alice"), new PersonDto("Bill")));
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getPassengers()).hasSize(2);
    assertThat(car.getPassengers().get(0).getName()).isEqualTo("Alice");
    assertThat(car.getPassengers().get(1).getName()).isEqualTo("Bill");
}
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 7 with Car

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

the class CarMapperTest method shouldMapEnumToString.

@ProcessorTest
public void shouldMapEnumToString() {
    // given
    Car car = new Car();
    car.setCategory(Category.CONVERTIBLE);
    // when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getCategory()).isEqualTo("CONVERTIBLE");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 8 with Car

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

the class CarMapperTest method shouldMapIterable.

@ProcessorTest
public void shouldMapIterable() {
    // given
    Car car1 = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), new ArrayList<>());
    Car car2 = new Car("Railton", 4, new GregorianCalendar(1934, Calendar.JANUARY, 1).getTime(), new Person("Bill"), new ArrayList<>());
    // when
    List<CarDto> dtos = CarMapper.INSTANCE.carsToCarDtos(Arrays.asList(car1, car2));
    // then
    assertThat(dtos).isNotNull();
    assertThat(dtos).hasSize(2);
    assertThat(dtos.get(0).getMake()).isEqualTo("Morris");
    assertThat(dtos.get(0).getSeatCount()).isEqualTo(2);
    assertThat(dtos.get(0).getManufacturingYear()).isEqualTo("1980");
    assertThat(dtos.get(0).getDriver().getName()).isEqualTo("Bob");
    assertThat(dtos.get(1).getMake()).isEqualTo("Railton");
    assertThat(dtos.get(1).getSeatCount()).isEqualTo(4);
    assertThat(dtos.get(1).getManufacturingYear()).isEqualTo("1934");
    assertThat(dtos.get(1).getDriver().getName()).isEqualTo("Bill");
}
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 9 with Car

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

the class CarMapperTest method shouldApplyConverter.

@ProcessorTest
public void shouldApplyConverter() {
    // 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.getManufacturingYear()).isEqualTo("1980");
}
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 10 with Car

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

the class CarMapperTest method shouldMapAttributeByName.

@ProcessorTest
public void shouldMapAttributeByName() {
    // 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.getMake()).isEqualTo(car.getMake());
}
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)

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