Search in sources :

Example 66 with ProcessorTest

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();
}
Also used : DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) CarDto(org.mapstruct.ap.test.nullvaluemapping._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 67 with ProcessorTest

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();
}
Also used : DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 68 with ProcessorTest

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();
}
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 69 with ProcessorTest

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();
}
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 70 with ProcessorTest

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");
}
Also used : BigInteger(java.math.BigInteger) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10