1717 FooMapper .class ,
1818 FooMapperConfigured .class ,
1919 FooSource .class ,
20- FooTarget .class
20+ FooTarget .class ,
21+ FooSourceNested .class
2122})
2223@ IssueKey ("3133" )
2324public class RedundantNullCheckTest {
2425 @ RegisterExtension
2526 final GeneratedSource generatedSource = new GeneratedSource ();
27+ private final String ls = lineSeparator ();
2628
2729 @ ProcessorTest
2830 @ IssueKey ("3133" )
2931 void shouldNotCreateRedundantNullCheckWithAdditionalPrimitiveParameters () {
30- String ls = lineSeparator ();
3132 generatedSource .forMapper ( FooMapper .class )
3233 .content ()
3334 .contains ( "@Override" + ls +
@@ -40,10 +41,82 @@ void shouldNotCreateRedundantNullCheckWithAdditionalPrimitiveParameters() {
4041 " }" );
4142 }
4243
44+ @ ProcessorTest
45+ @ IssueKey ("3133" )
46+ void shouldNotCreateRedundantNullCheckWithMultipleAdditionalPrimitiveParameters () {
47+ generatedSource .forMapper ( FooMapper .class )
48+ .content ()
49+ .contains ( "@Override" + ls +
50+ " public void updateFoo(FooSource input, FooTarget toUpdate, boolean baz, int bay) {" + ls +
51+ " if ( input == null ) {" + ls +
52+ " return;" + ls +
53+ " }" + ls +
54+ ls +
55+ " toUpdate.setBar( input.getBar() );" + ls +
56+ " }" );
57+ }
58+
59+ @ ProcessorTest
60+ @ IssueKey ("3133" )
61+ void shouldNotCreateRedundantNullCheckWithReturnValue () {
62+ generatedSource .forMapper ( FooMapper .class )
63+ .content ()
64+ .contains ( "@Override" + ls +
65+ " public FooTarget getUpdatedFooTarget(FooSource input, FooTarget toUpdate) {" + ls +
66+ " if ( input == null ) {" + ls +
67+ " return toUpdate;" + ls +
68+ " }" + ls +
69+ ls +
70+ " toUpdate.setBar( input.getBar() );" + ls +
71+ ls +
72+ " return toUpdate;" + ls +
73+ " }" );
74+ }
75+
76+ @ ProcessorTest
77+ @ IssueKey ("3133" )
78+ void shouldNotCreateRedundantNullCheckWithReturnValueWithAdditionalPrimitiveParameters () {
79+ generatedSource .forMapper ( FooMapper .class )
80+ .content ()
81+ .contains ( "@Override" + ls +
82+ " public FooTarget getUpdatedFooTarget(FooSource input, FooTarget toUpdate, boolean baz) {" + ls +
83+ " if ( input == null ) {" + ls +
84+ " return toUpdate;" + ls +
85+ " }" + ls +
86+ ls +
87+ " toUpdate.setBar( input.getBar() );" + ls +
88+ ls +
89+ " return toUpdate;" + ls +
90+ " }" );
91+ }
92+
93+ @ ProcessorTest
94+ @ IssueKey ("3133" )
95+ void shouldNotCreateRedundantNullCheckForNestedSourceWithReturnValueWithAdditionalPrimitiveParameters () {
96+ generatedSource .forMapper ( FooMapper .class )
97+ .content ()
98+ .containsIgnoringWhitespaces ( "@Override" + ls +
99+ " public FooTarget map(FooSourceNested input, FooTarget toUpdate, boolean baz) {" + ls +
100+ " if ( input == null ) {" + ls +
101+ " return toUpdate;" + ls +
102+ " }" + ls +
103+ ls +
104+ " toUpdate.setBar( inputNestedBar( input ) );" + ls +
105+ ls +
106+ " return toUpdate;" + ls +
107+ " }" + ls +
108+ " private String inputNestedBar(FooSourceNested fooSourceNested) {" + ls +
109+ " FooSource nested = fooSourceNested.getNested();" + ls +
110+ " if ( nested == null ) {" + ls +
111+ " return null;" + ls +
112+ " }" + ls +
113+ " return nested.getBar();" + ls +
114+ " }" );
115+ }
116+
43117 @ ProcessorTest
44118 @ IssueKey ("3133" )
45119 void shouldNotCreateRedundantNullCheck () {
46- String ls = lineSeparator ();
47120 generatedSource .forMapper ( FooMapper .class )
48121 .content ()
49122 .contains ( "@Override" + ls +
@@ -56,10 +129,10 @@ void shouldNotCreateRedundantNullCheck() {
56129 " }" );
57130 }
58131
132+
59133 @ ProcessorTest
60134 @ IssueKey ("3133" )
61135 void shouldCreateNullCheckIfNoGuardClauseIsPresentWithAdditionalPrimitiveParameters () {
62- String ls = lineSeparator ();
63136 generatedSource .forMapper ( FooMapperConfigured .class )
64137 .content ()
65138 .contains ( "@Override" + ls +
@@ -74,7 +147,6 @@ void shouldCreateNullCheckIfNoGuardClauseIsPresentWithAdditionalPrimitiveParamet
74147 @ ProcessorTest
75148 @ IssueKey ("3133" )
76149 void shouldCreateNullCheckIfNoGuardClauseIsPresent () {
77- String ls = lineSeparator ();
78150 generatedSource .forMapper ( FooMapperConfigured .class )
79151 .content ()
80152 .contains ( "@Override" + ls +
@@ -86,4 +158,24 @@ void shouldCreateNullCheckIfNoGuardClauseIsPresent() {
86158 " }" );
87159 }
88160
161+ @ ProcessorTest
162+ @ IssueKey ("3133" )
163+ void shouldCreateNullCheckIfNoGuardClauseIsPresentForNestedTargetClass () {
164+ generatedSource .forMapper ( FooMapper .class )
165+ .content ()
166+ .contains ( "@Override" + ls +
167+ " public FooTarget map(FooSourceNested source) {" + ls +
168+ " if ( source == null ) {" + ls +
169+ " return null;" + ls +
170+ " }" + ls +
171+ ls +
172+ " FooTarget fooTarget = new FooTarget();" + ls +
173+ ls +
174+ " fooTarget.setBar( source.getBar() );" + ls +
175+ ls +
176+ " return fooTarget;" + ls +
177+ " }" );
178+ }
179+
180+
89181}
0 commit comments