Search in sources :

Example 16 with CarDto

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

the class CarMapperTest method shouldMapEnumToString.

@ProcessorTest
public void shouldMapEnumToString() {
    // given
    Car car = new Car();
    car.setCategory(Category.CONVERTIBLE);
    // when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getCategory()).isEqualTo("CONVERTIBLE");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) CarDto(org.mapstruct.ap.test.complex._target.CarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 17 with CarDto

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

the class CarMapperTest method shouldMapIterable.

@ProcessorTest
public void shouldMapIterable() {
    // given
    Car car1 = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), new ArrayList<>());
    Car car2 = new Car("Railton", 4, new GregorianCalendar(1934, Calendar.JANUARY, 1).getTime(), new Person("Bill"), new ArrayList<>());
    // when
    List<CarDto> dtos = CarMapper.INSTANCE.carsToCarDtos(Arrays.asList(car1, car2));
    // then
    assertThat(dtos).isNotNull();
    assertThat(dtos).hasSize(2);
    assertThat(dtos.get(0).getMake()).isEqualTo("Morris");
    assertThat(dtos.get(0).getSeatCount()).isEqualTo(2);
    assertThat(dtos.get(0).getManufacturingYear()).isEqualTo("1980");
    assertThat(dtos.get(0).getDriver().getName()).isEqualTo("Bob");
    assertThat(dtos.get(1).getMake()).isEqualTo("Railton");
    assertThat(dtos.get(1).getSeatCount()).isEqualTo(4);
    assertThat(dtos.get(1).getManufacturingYear()).isEqualTo("1934");
    assertThat(dtos.get(1).getDriver().getName()).isEqualTo("Bill");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) Person(org.mapstruct.ap.test.complex.source.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 18 with CarDto

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

the class CarMapperTest method shouldApplyConverter.

@ProcessorTest
public void shouldApplyConverter() {
    // given
    Car car = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), new ArrayList<>());
    // when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getManufacturingYear()).isEqualTo("1980");
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) Person(org.mapstruct.ap.test.complex.source.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 19 with CarDto

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

the class CarMapperTest method shouldMapAttributeByName.

@ProcessorTest
public void shouldMapAttributeByName() {
    // given
    Car car = new Car("Morris", 2, new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), new Person("Bob"), new ArrayList<>());
    // when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto).isNotNull();
    assertThat(carDto.getMake()).isEqualTo(car.getMake());
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) GregorianCalendar(java.util.GregorianCalendar) CarDto(org.mapstruct.ap.test.complex._target.CarDto) Person(org.mapstruct.ap.test.complex.source.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 20 with CarDto

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

the class CarMapperTest method shouldMapStringToEnum.

@ProcessorTest
public void shouldMapStringToEnum() {
    // given
    CarDto carDto = new CarDto();
    carDto.setCategory("CONVERTIBLE");
    // when
    Car car = CarMapper.INSTANCE.carDtoToCar(carDto);
    // then
    assertThat(car).isNotNull();
    assertThat(car.getCategory()).isEqualTo(Category.CONVERTIBLE);
}
Also used : Car(org.mapstruct.ap.test.complex.source.Car) CarDto(org.mapstruct.ap.test.complex._target.CarDto) 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