forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mapstruct#3747 Do not generate redundant if condition with constructo…
…r mapping and RETURN_DEFAULT null value mapping strategy
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Mapper.java
This file contains 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,42 @@ | ||
/* | ||
* 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.bugs._3747; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.NullValueMappingStrategy; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) | ||
public interface Issue3747Mapper { | ||
|
||
Target map(Source source); | ||
|
||
class Source { | ||
private final String value; | ||
|
||
public Source(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
|
||
class Target { | ||
private final String value; | ||
|
||
public Target(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Test.java
This file contains 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,28 @@ | ||
/* | ||
* 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.bugs._3747; | ||
|
||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.ProcessorTest; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.ap.testutil.runner.GeneratedSource; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@IssueKey("3747") | ||
@WithClasses(Issue3747Mapper.class) | ||
class Issue3747Test { | ||
|
||
@RegisterExtension | ||
final GeneratedSource generatedSource = new GeneratedSource(); | ||
|
||
@ProcessorTest | ||
void shouldNotGenerateObsoleteCode() { | ||
generatedSource.addComparisonToFixtureFor( Issue3747Mapper.class ); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...sor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3747/Issue3747MapperImpl.java
This file contains 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,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.bugs._3747; | ||
|
||
import javax.annotation.processing.Generated; | ||
|
||
@Generated( | ||
value = "org.mapstruct.ap.MappingProcessor", | ||
date = "2024-11-03T12:50:02+0100", | ||
comments = "version: , compiler: javac, environment: Java 21.0.3 (N/A)" | ||
) | ||
public class Issue3747MapperImpl implements Issue3747Mapper { | ||
|
||
@Override | ||
public Target map(Source source) { | ||
|
||
String value = null; | ||
if ( source != null ) { | ||
value = source.getValue(); | ||
} | ||
|
||
Target target = new Target( value ); | ||
|
||
return target; | ||
} | ||
} |