Search in sources :

Example 1 with Car

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

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

Aggregations

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