-
-
Notifications
You must be signed in to change notification settings - Fork 1k
#3309 - Add BeanMapping#unmappedSourcePolicy
#3326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6df95d0
Add unmappedSourcePolicy to BeanMapping (#3309)
venkatesh2090 89741c2
Added tests for BeanMapping#unmappedSourcePolicy (#3309)
venkatesh2090 eb4c3ec
Merge branch 'main' into issue-3309
venkatesh2090 092983a
Address PR comments (#3309)
venkatesh2090 08a0308
Added license to BeanMappingSourcePolicyMapper (#3309)
venkatesh2090 11ec9cc
Added more test and updated Javadoc for BeanMapping (#3309)
venkatesh2090 fb1d93d
Fix checkstyle errors (#3309)
venkatesh2090 082251f
Renamed class for int tests (#3309)
venkatesh2090 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyErroneousMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * 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.unmappedsource.beanmapping; | ||
|
|
||
| import org.mapstruct.BeanMapping; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.ReportingPolicy; | ||
|
|
||
| @Mapper(unmappedSourcePolicy = ReportingPolicy.WARN) | ||
| public interface BeanMappingSourcePolicyErroneousMapper { | ||
|
|
||
| @BeanMapping(unmappedSourcePolicy = ReportingPolicy.ERROR) | ||
| Target map(Source source); | ||
|
|
||
| } |
25 changes: 25 additions & 0 deletions
25
.../java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * 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.unmappedsource.beanmapping; | ||
|
|
||
| import org.mapstruct.BeanMapping; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.ReportingPolicy; | ||
| import org.mapstruct.factory.Mappers; | ||
|
|
||
| @Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) | ||
| public interface BeanMappingSourcePolicyMapper { | ||
|
|
||
| BeanMappingSourcePolicyMapper MAPPER = | ||
| Mappers.getMapper( BeanMappingSourcePolicyMapper.class ); | ||
|
|
||
| @BeanMapping(unmappedSourcePolicy = ReportingPolicy.WARN) | ||
| Target map(Source source); | ||
|
|
||
| @BeanMapping(unmappedSourcePolicy = ReportingPolicy.IGNORE) | ||
| Target map2(Source source); | ||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
30
processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Source.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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.unmappedsource.beanmapping; | ||
|
|
||
| public class Source { | ||
|
|
||
| private int foo; | ||
|
|
||
| private int bar; | ||
|
|
||
| public int getFoo() { | ||
| return foo; | ||
| } | ||
|
|
||
| public void setFoo(int foo) { | ||
| this.foo = foo; | ||
| } | ||
|
|
||
| public int getBar() { | ||
| return bar; | ||
| } | ||
|
|
||
| public void setBar(int bar) { | ||
| this.bar = bar; | ||
| } | ||
|
|
||
| } |
20 changes: 20 additions & 0 deletions
20
processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Target.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * 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.unmappedsource.beanmapping; | ||
|
|
||
| public class Target { | ||
|
|
||
| private int foo; | ||
|
|
||
| public int getFoo() { | ||
| return foo; | ||
| } | ||
|
|
||
| public void setFoo(int foo) { | ||
| this.foo = foo; | ||
| } | ||
|
|
||
| } |
67 changes: 67 additions & 0 deletions
67
...or/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/UnmappedSourceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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.unmappedsource.beanmapping; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import javax.tools.Diagnostic.Kind; | ||
|
|
||
| import org.mapstruct.ap.testutil.IssueKey; | ||
| import org.mapstruct.ap.testutil.ProcessorTest; | ||
| import org.mapstruct.ap.testutil.WithClasses; | ||
| import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; | ||
| import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; | ||
| import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; | ||
|
|
||
| @IssueKey("3309") | ||
| class UnmappedSourceTest { | ||
|
|
||
| @ProcessorTest | ||
| @WithClasses({ Source.class, Target.class, BeanMappingSourcePolicyMapper.class }) | ||
| @ExpectedCompilationOutcome( | ||
| value = CompilationResult.SUCCEEDED, | ||
| diagnostics = { | ||
| @Diagnostic(type = BeanMappingSourcePolicyMapper.class, | ||
| kind = Kind.WARNING, | ||
| line = 20, | ||
| message = "Unmapped source property: \"bar\".") | ||
| } | ||
| ) | ||
| public void shouldCompileWithUnmappedSourcePolicySetToWarnWithBeanMapping() { | ||
| Source source = new Source(); | ||
| Source source2 = new Source(); | ||
|
|
||
| source.setFoo( 10 ); | ||
| source.setBar( 20 ); | ||
|
|
||
| source2.setFoo( 1 ); | ||
| source2.setBar( 2 ); | ||
|
|
||
| Target target = BeanMappingSourcePolicyMapper.MAPPER.map( source ); | ||
| Target target2 = BeanMappingSourcePolicyMapper.MAPPER.map2( source2 ); | ||
|
|
||
| assertThat( target ).isNotNull(); | ||
| assertThat( target.getFoo() ).isEqualTo( 10 ); | ||
|
|
||
| assertThat( target2 ).isNotNull(); | ||
| assertThat( target2.getFoo() ).isEqualTo( 1 ); | ||
| } | ||
|
|
||
| @ProcessorTest | ||
| @WithClasses({ Source.class, Target.class, BeanMappingSourcePolicyErroneousMapper.class }) | ||
| @ExpectedCompilationOutcome( | ||
| value = CompilationResult.FAILED, | ||
| diagnostics = { | ||
| @Diagnostic(type = BeanMappingSourcePolicyErroneousMapper.class, | ||
| kind = Kind.ERROR, | ||
| line = 16, | ||
| message = "Unmapped source property: \"bar\".") | ||
| } | ||
| ) | ||
| public void shouldErrorWithUnmappedSourcePolicySetToErrorWithBeanMapping() { | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.