mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Add test case for demonstrating how the ignoreByDefault can be overridden from the base configuration
This commit is contained in:
parent
36349c49e9
commit
28017e2b0c
@ -56,7 +56,7 @@ public class IgnorePropertyTest {
|
||||
|
||||
@Test
|
||||
@IssueKey("1933")
|
||||
public void shouldIgnoreBase() {
|
||||
public void shouldInheritIgnoreByDefaultFromBase() {
|
||||
|
||||
WorkBenchDto workBenchDto = new WorkBenchDto();
|
||||
workBenchDto.setArticleName( "MyBench" );
|
||||
@ -74,4 +74,24 @@ public class IgnorePropertyTest {
|
||||
assertThat( benchTarget.getCreationDate() ).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IssueKey("1933")
|
||||
public void shouldOnlyIgnoreBase() {
|
||||
|
||||
WorkBenchDto workBenchDto = new WorkBenchDto();
|
||||
workBenchDto.setArticleName( "MyBench" );
|
||||
workBenchDto.setArticleDescription( "Beautiful" );
|
||||
workBenchDto.setCreationDate( new Date() );
|
||||
workBenchDto.setModificationDate( new Date() );
|
||||
|
||||
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBenchWithImplicit( workBenchDto );
|
||||
|
||||
assertThat( benchTarget ).isNotNull();
|
||||
assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" );
|
||||
assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" );
|
||||
assertThat( benchTarget.getKey() ).isNull();
|
||||
assertThat( benchTarget.getModificationDate() ).isNull();
|
||||
assertThat( benchTarget.getCreationDate() ).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,12 +29,21 @@ public interface ToolMapper {
|
||||
@InheritConfiguration( name = "mapBase" )
|
||||
ToolEntity mapTool(ToolDto source);
|
||||
|
||||
// demonstrates that all the business stuff is mapped (implicit-by-name and defined)
|
||||
// demonstrates that all the business stuff is mapped only defined because BeanMapping#ignoreByDefault
|
||||
@InheritConfiguration( name = "mapBase" )
|
||||
@Mapping(target = "description", source = "articleDescription")
|
||||
WorkBenchEntity mapBench(WorkBenchDto source);
|
||||
|
||||
// demonstrates that all the business stuff is mapped (implicit-by-name and defined)
|
||||
@BeanMapping( ignoreByDefault = false ) // needed to override the one from the BeanMapping mapBase
|
||||
@InheritConfiguration( name = "mapBase" )
|
||||
@Mapping(target = "description", source = "articleDescription")
|
||||
WorkBenchEntity mapBenchWithImplicit(WorkBenchDto source);
|
||||
|
||||
// ignore all the base properties by default
|
||||
@BeanMapping( ignoreByDefault = true )
|
||||
@Mapping( target = "key", ignore = true)
|
||||
@Mapping( target = "modificationDate", ignore = true)
|
||||
@Mapping( target = "creationDate", ignore = true)
|
||||
BaseEntity mapBase(Object o);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user