Search in sources :

Example 1 with VehicleCollection

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

the class SubclassMappingTest method mappingIsDoneUsingSubclassMapping.

@ProcessorTest
@WithClasses(SimpleSubclassMapper.class)
void mappingIsDoneUsingSubclassMapping() {
    VehicleCollection vehicles = new VehicleCollection();
    vehicles.getVehicles().add(new Car());
    vehicles.getVehicles().add(new Bike());
    VehicleCollectionDto result = SimpleSubclassMapper.INSTANCE.map(vehicles);
    assertThat(result.getVehicles()).doesNotContainNull();
    // remove generic so that test works.
    assertThat(result.getVehicles()).extracting(vehicle -> (Class) vehicle.getClass()).containsExactly(CarDto.class, BikeDto.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) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with VehicleCollection

use of org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection 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 3 with VehicleCollection

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

the class SubclassMappingTest method existingMappingsAreUsedWhenFound.

@ProcessorTest
@WithClasses(SubclassMapperUsingExistingMappings.class)
void existingMappingsAreUsedWhenFound() {
    VehicleCollection vehicles = new VehicleCollection();
    vehicles.getVehicles().add(new Car());
    VehicleCollectionDto result = SubclassMapperUsingExistingMappings.INSTANCE.map(vehicles);
    assertThat(result.getVehicles()).extracting(VehicleDto::getName).containsExactly("created through existing mapping.");
}
Also used : Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with VehicleCollection

use of org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection 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 5 with VehicleCollection

use of org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection 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

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