Search in sources :

Example 1 with Person

use of org.mapstruct.ap.test.complex.source.Person 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 2 with Person

use of org.mapstruct.ap.test.complex.source.Person 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 3 with Person

use of org.mapstruct.ap.test.complex.source.Person 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 4 with Person

use of org.mapstruct.ap.test.complex.source.Person 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)

Example 5 with Person

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

the class CarMapperTest method shouldMapAttributeWithCustomMapping.

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

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