mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Add test case for subclass mapping and bean mapping ignore by default
This commit is contained in:
parent
0460c373c0
commit
28d827a724
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.subclassmapping;
|
||||
|
||||
import org.mapstruct.BeanMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.SubclassMapping;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.Bike;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.Car;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.CarDto;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle;
|
||||
import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface SubclassIgnoreByDefaultMapper {
|
||||
SubclassIgnoreByDefaultMapper INSTANCE = Mappers.getMapper( SubclassIgnoreByDefaultMapper.class );
|
||||
|
||||
@BeanMapping(ignoreByDefault = true)
|
||||
@SubclassMapping(source = Car.class, target = CarDto.class)
|
||||
@SubclassMapping(source = Bike.class, target = BikeDto.class)
|
||||
@Mapping(target = "name")
|
||||
VehicleDto map(Vehicle vehicle);
|
||||
}
|
@ -277,4 +277,18 @@ public class SubclassMappingTest {
|
||||
})
|
||||
void inverseSubclassMappingNotPossible() {
|
||||
}
|
||||
|
||||
@ProcessorTest
|
||||
@WithClasses(SubclassIgnoreByDefaultMapper.class)
|
||||
void beanMappingIgnoreByDefaultShouldBePropagated() {
|
||||
Car car = new Car();
|
||||
car.setName( "Test car" );
|
||||
car.setManual( true );
|
||||
VehicleDto target = SubclassIgnoreByDefaultMapper.INSTANCE.map( car );
|
||||
assertThat( target )
|
||||
.isInstanceOfSatisfying( CarDto.class, carDto -> {
|
||||
assertThat( carDto.getName() ).isEqualTo( "Test car" );
|
||||
assertThat( carDto.isManual() ).isFalse();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user