From 28017e2b0ca99793b1bf8da933ec0811b75c3635 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Jul 2020 15:01:49 +0200 Subject: [PATCH] Add test case for demonstrating how the ignoreByDefault can be overridden from the base configuration --- .../ignore/inherit/IgnorePropertyTest.java | 22 ++++++++++++++++++- .../ap/test/ignore/inherit/ToolMapper.java | 11 +++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java index 7dce466b4..ef0cf6fc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java @@ -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(); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java index ca7da9b99..10c3a513f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java @@ -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); }