Search in sources :

Example 1 with CarDto

use of org.mapstruct.ap.test.subclassmapping.mappables.CarDto in project mapstruct by mapstruct.

the class SubclassMappingTest method subclassMappingOverridesInverseInheritsMapping.

@ProcessorTest
@WithClasses({ HatchBack.class, InverseOrderSubclassMapper.class })
void subclassMappingOverridesInverseInheritsMapping() {
    VehicleCollectionDto vehicleDtos = new VehicleCollectionDto();
    CarDto carDto = new CarDto();
    carDto.setMaker("BenZ");
    vehicleDtos.getVehicles().add(carDto);
    VehicleCollection result = InverseOrderSubclassMapper.INSTANCE.mapInverse(vehicleDtos);
    // remove generic so that test works.
    assertThat(result.getVehicles()).extracting(vehicle -> (Class) vehicle.getClass()).containsExactly(Car.class);
}
Also used : HatchBackDto(org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) Diagnostic(org.mapstruct.ap.testutil.compilation.annotation.Diagnostic) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HatchBack(org.mapstruct.ap.test.subclassmapping.mappables.HatchBack) VehicleDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto) WithClasses(org.mapstruct.ap.testutil.WithClasses) BikeDto(org.mapstruct.ap.test.subclassmapping.mappables.BikeDto) Vehicle(org.mapstruct.ap.test.subclassmapping.mappables.Vehicle) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) IssueKey(org.mapstruct.ap.testutil.IssueKey) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) CompilationResult(org.mapstruct.ap.testutil.compilation.annotation.CompilationResult) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with CarDto

use of org.mapstruct.ap.test.subclassmapping.mappables.CarDto in project mapstruct by mapstruct.

the class SubclassMapperUsingExistingMappings method existingMappingMethod.

default CarDto existingMappingMethod(Car domain) {
    CarDto dto = new CarDto();
    dto.setName("created through existing mapping.");
    return dto;
}
Also used : CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto)

Example 3 with CarDto

use of org.mapstruct.ap.test.subclassmapping.mappables.CarDto in project mapstruct by mapstruct.

the class SubclassMappingTest method subclassMappingInheritsInverseMapping.

@ProcessorTest
@WithClasses(SimpleSubclassMapper.class)
void subclassMappingInheritsInverseMapping() {
    VehicleCollectionDto vehiclesDto = new VehicleCollectionDto();
    CarDto carDto = new CarDto();
    carDto.setMaker("BenZ");
    vehiclesDto.getVehicles().add(carDto);
    VehicleCollection result = SimpleSubclassMapper.INSTANCE.mapInverse(vehiclesDto);
    assertThat(result.getVehicles()).extracting(Vehicle::getVehicleManufacturingCompany).containsExactly("BenZ");
}
Also used : VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with CarDto

use of org.mapstruct.ap.test.subclassmapping.mappables.CarDto in project mapstruct by mapstruct.

the class SubclassMappingTest method inverseMappingIsDoneUsingSubclassMapping.

@ProcessorTest
@WithClasses(SimpleSubclassMapper.class)
void inverseMappingIsDoneUsingSubclassMapping() {
    VehicleCollectionDto vehicles = new VehicleCollectionDto();
    vehicles.getVehicles().add(new CarDto());
    vehicles.getVehicles().add(new BikeDto());
    VehicleCollection result = SimpleSubclassMapper.INSTANCE.mapInverse(vehicles);
    assertThat(result.getVehicles()).doesNotContainNull();
    // remove generic so that test works.
    assertThat(result.getVehicles()).extracting(vehicle -> (Class) vehicle.getClass()).containsExactly(Car.class, Bike.class);
}
Also used : HatchBackDto(org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) Diagnostic(org.mapstruct.ap.testutil.compilation.annotation.Diagnostic) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HatchBack(org.mapstruct.ap.test.subclassmapping.mappables.HatchBack) VehicleDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto) WithClasses(org.mapstruct.ap.testutil.WithClasses) BikeDto(org.mapstruct.ap.test.subclassmapping.mappables.BikeDto) Vehicle(org.mapstruct.ap.test.subclassmapping.mappables.Vehicle) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) IssueKey(org.mapstruct.ap.testutil.IssueKey) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) CompilationResult(org.mapstruct.ap.testutil.compilation.annotation.CompilationResult) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) BikeDto(org.mapstruct.ap.test.subclassmapping.mappables.BikeDto) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

CarDto (org.mapstruct.ap.test.subclassmapping.mappables.CarDto)4 VehicleCollection (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection)3 VehicleCollectionDto (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto)3 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)3 WithClasses (org.mapstruct.ap.testutil.WithClasses)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Bike (org.mapstruct.ap.test.subclassmapping.mappables.Bike)2 BikeDto (org.mapstruct.ap.test.subclassmapping.mappables.BikeDto)2 Car (org.mapstruct.ap.test.subclassmapping.mappables.Car)2 HatchBack (org.mapstruct.ap.test.subclassmapping.mappables.HatchBack)2 HatchBackDto (org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto)2 Vehicle (org.mapstruct.ap.test.subclassmapping.mappables.Vehicle)2 VehicleDto (org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto)2 IssueKey (org.mapstruct.ap.testutil.IssueKey)2 CompilationResult (org.mapstruct.ap.testutil.compilation.annotation.CompilationResult)2 Diagnostic (org.mapstruct.ap.testutil.compilation.annotation.Diagnostic)2 ExpectedCompilationOutcome (org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome)2