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);
}
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);
}
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.");
}
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");
}
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);
}
Aggregations