Search in sources :

Example 11 with Car

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

the class CarMapperTest method shouldMapStringToEnum.

@ProcessorTest
public void shouldMapStringToEnum() {
    // given
    CarDto carDto = new CarDto();
    carDto.setCategory("CONVERTIBLE");
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getCategory()).isEqualTo(Category.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 12 with Car

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

Example 13 with Car

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

the class CarMapperTest method shouldMapIterableAttribute.

@ProcessorTest
public void shouldMapIterableAttribute() {
    // given
    Car car = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), Arrays.asList(new Person("Alice"), new Person("Bill")));
    // when
    CarDto dto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(dto).isNotNull();
    assertThat(dto.getPassengers()).hasSize(2);
    assertThat(dto.getPassengers().get(0).getName()).isEqualTo("Alice");
    assertThat(dto.getPassengers().get(1).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)

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