Search in sources :

Example 1 with CarDto

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

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

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

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

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

the class InheritedMappingMethodTest method shouldMapUsingUnboundedInheretedMappingMethod.

@ProcessorTest
public void shouldMapUsingUnboundedInheretedMappingMethod() {
    // given
    CarDto bikeDto = new CarDto();
    bikeDto.setHorsepower(130);
    // when
    UnboundMappable<CarDto, Car> instance = CarMapper.INSTANCE;
    Car bike = instance.from(bikeDto);
    // then
    assertThat(bike).isNotNull();
    assertThat(bike.getHorsepower()).isEqualTo(130);
}
Also used : Car(org.mapstruct.ap.test.inheritedmappingmethod.source.Car) FastCar(org.mapstruct.ap.test.inheritedmappingmethod.source.FastCar) CarDto(org.mapstruct.ap.test.inheritedmappingmethod._target.CarDto) FastCarDto(org.mapstruct.ap.test.inheritedmappingmethod._target.FastCarDto) 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