use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessNullArgOnMapper.
@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessNullArgOnMapper() {
// when
CarDto carDto = CarMapperSettingOnMapper.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();
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class NullValueMappingTest method shouldApplyConfiguredStrategyForMethodWithSeveralSourceParams.
@ProcessorTest
public void shouldApplyConfiguredStrategyForMethodWithSeveralSourceParams() {
// when
DriverAndCarDto result = CarMapper.INSTANCE.driverAndCarToDto(null, null);
// then
assertThat(result).isNotNull();
assertThat(result.getMake()).isNull();
assertThat(result.getName()).isNull();
// when
result = CarMapper.INSTANCE.driverAndCarToDtoReturningNull(null, null);
// then
assertThat(result).isNull();
}
use of org.mapstruct.ap.testutil.ProcessorTest 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.testutil.ProcessorTest 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.testutil.ProcessorTest in project mapstruct by mapstruct.
the class WildCardTest method testWildCardAsSourceType.
@ProcessorTest
@WithClasses(SourceWildCardExtendsMapper.class)
public void testWildCardAsSourceType() {
// prepare source
SourceWildCardExtendsMapper.Wrapper<BigInteger> wrapper = new SourceWildCardExtendsMapper.Wrapper<>(new BigInteger("5"));
SourceWildCardExtendsMapper.Source source = new SourceWildCardExtendsMapper.Source(wrapper);
// action
SourceWildCardExtendsMapper.Target target = SourceWildCardExtendsMapper.INSTANCE.map(source);
// verify target
assertThat(target).isNotNull();
assertThat(target.getProp()).isEqualTo("5");
}
Aggregations