Search in sources :

Example 1 with Car

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

the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessNullArg.

@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessNullArg() {
    // given
    Car car = new Car("Morris", 2);
    // when
    CarDto carDto1 = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto1).isNotNull();
    assertThat(carDto1.getMake()).isEqualTo(car.getMake());
    assertThat(carDto1.getSeatCount()).isEqualTo(car.getNumberOfSeats());
    assertThat(carDto1.getModel()).isEqualTo("ModelT");
    assertThat(carDto1.getCatalogId()).isNotEmpty();
    // when
    CarDto carDto2 = CarMapper.INSTANCE.carToCarDto(null);
    // then
    assertThat(carDto2).isNotNull();
    assertThat(carDto2.getMake()).isNull();
    assertThat(carDto2.getSeatCount()).isEqualTo(0);
    assertThat(carDto2.getModel()).isEqualTo("ModelT");
    assertThat(carDto2.getCatalogId()).isNotEmpty();
}
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 2 with Car

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

the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessNullArgSeveralSources.

@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessNullArgSeveralSources() {
    // given
    Car car = new Car("Morris", 2);
    // when
    CarDto carDto1 = CarMapper.INSTANCE.carToCarDto(car, "ModelT");
    // then
    assertThat(carDto1).isNotNull();
    assertThat(carDto1.getMake()).isEqualTo(car.getMake());
    assertThat(carDto1.getModel()).isEqualTo("ModelT");
    assertThat(carDto1.getSeatCount()).isEqualTo(car.getNumberOfSeats());
    assertThat(carDto1.getCatalogId()).isNotEmpty();
    // when
    CarDto carDto2 = CarMapper.INSTANCE.carToCarDto(null, "ModelT");
    // then
    assertThat(carDto2).isNotNull();
    assertThat(carDto2.getMake()).isNull();
    assertThat(carDto2.getSeatCount()).isEqualTo(0);
    assertThat(carDto2.getModel()).isEqualTo("ModelT");
    assertThat(carDto2.getCatalogId()).isNotEmpty();
}
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 3 with Car

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

the class NullValueMappingTest method shouldMapMapWithNullArg.

@ProcessorTest
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldMapMapWithNullArg() {
    // given
    Car car = new Car("Morris", 2);
    Map carMap = new HashMap();
    carMap.put(1, car);
    // when
    Map<Integer, CarDto> carDtoMap1 = CarMapper.INSTANCE.carsToCarDtoMap(carMap);
    // then
    assertThat(carDtoMap1).isNotNull();
    assertThat(carDtoMap1.size()).isEqualTo(1);
    // when
    Map<Integer, CarDto> carDtoMap2 = CarMapper.INSTANCE.carsToCarDtoMap(null);
    // then
    assertThat(carDtoMap2).isNotNull();
    assertThat(carDtoMap2.isEmpty()).isTrue();
}
Also used : Car(org.mapstruct.ap.test.nullvaluemapping.source.Car) HashMap(java.util.HashMap) DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) CarDto(org.mapstruct.ap.test.nullvaluemapping._target.CarDto) Map(java.util.Map) HashMap(java.util.HashMap) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 4 with Car

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

Aggregations

CarDto (org.mapstruct.ap.test.nullvaluemapping._target.CarDto)4 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)4 Car (org.mapstruct.ap.test.nullvaluemapping.source.Car)4 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1