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();
}
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();
}
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();
}
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();
}
Aggregations