Search in sources :

Example 21 with CarDto

use of org.mapstruct.ap.test.complex._target.CarDto 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 22 with CarDto

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

Example 23 with CarDto

use of org.mapstruct.ap.test.complex._target.CarDto in project mapstruct by mapstruct.

the class NullValueMappingTest method shouldMapIterableWithNullArg.

@ProcessorTest
public void shouldMapIterableWithNullArg() {
    // given
    Car car = new Car("Morris", 2);
    // when
    List<CarDto> carDtos1 = CarMapper.INSTANCE.carsToCarDtos(Arrays.asList(car));
    // then
    assertThat(carDtos1).isNotNull();
    assertThat(carDtos1.size()).isEqualTo(1);
    // when
    List<CarDto> carDtos2 = CarMapper.INSTANCE.carsToCarDtos(null);
    // then
    assertThat(carDtos2).isNotNull();
    assertThat(carDtos2.isEmpty()).isTrue();
}
Also used : Car(org.mapstruct.ap.test.nullvaluemapping.source.Car) DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) CarDto(org.mapstruct.ap.test.nullvaluemapping._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 24 with CarDto

use of org.mapstruct.ap.test.complex._target.CarDto in project mapstruct by mapstruct.

the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessOfIterableNullArgOnMapper.

@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessOfIterableNullArgOnMapper() {
    // when
    CarDto carDto = CarMapperIterableSettingOnMapper.INSTANCE.carToCarDto(null);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getMake()).isNull();
    assertThat(carDto.getSeatCount()).isEqualTo(0);
    assertThat(carDto.getModel()).isEqualTo("ModelT");
    assertThat(carDto.getCatalogId()).isNotEmpty();
}
Also used : DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) CarDto(org.mapstruct.ap.test.nullvaluemapping._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)24 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 CarDto (org.mapstruct.ap.test.nullvaluemapping._target.CarDto)10 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)10 GregorianCalendar (java.util.GregorianCalendar)8 Person (org.mapstruct.ap.test.complex.source.Person)6 PersonDto (org.mapstruct.ap.test.complex._target.PersonDto)5 Car (org.mapstruct.ap.test.nullvaluemapping.source.Car)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CarDto (org.mapstruct.ap.test.inheritedmappingmethod._target.CarDto)1 FastCarDto (org.mapstruct.ap.test.inheritedmappingmethod._target.FastCarDto)1 Car (org.mapstruct.ap.test.inheritedmappingmethod.source.Car)1 FastCar (org.mapstruct.ap.test.inheritedmappingmethod.source.FastCar)1