forked from mapstruct/mapstruct
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mapstruct#131, mapstruct#2438: Brought the situation from issue 2438 …
…under test and fixed inheritence issues.
- Loading branch information
Showing
7 changed files
with
215 additions
and
22 deletions.
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
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
45 changes: 45 additions & 0 deletions
45
processor/src/test/java/org/mapstruct/ap/test/bugs/_2438/Issue2438Test.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,45 @@ | ||
/* | ||
* 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._2438; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.ProcessorTest; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@IssueKey( "2438" ) | ||
@WithClasses( { Source.class, SourceSubclass.class, SubclassMapper.class, Target.class } ) | ||
class Issue2438Test { | ||
|
||
@ProcessorTest | ||
void inheretenceTest() { | ||
SubclassMapper mapper = Mappers.getMapper( SubclassMapper.class ); | ||
SourceSubclass sourceSubclass = new SourceSubclass( "f1", "f2", "f3", "f4", "f5" ); | ||
|
||
Target result = mapper.mapSuperclass( sourceSubclass ); | ||
|
||
Assertions.assertThat( result.getTarget1() ).isEqualTo( "f1" ); | ||
Assertions.assertThat( result.getTarget2() ).isEqualTo( "f2" ); | ||
Assertions.assertThat( result.getTarget3() ).isEqualTo( "f3" ); | ||
Assertions.assertThat( result.getTarget4() ).isEqualTo( "f4" ); | ||
Assertions.assertThat( result.getTarget5() ).isEqualTo( "f5" ); | ||
} | ||
|
||
@ProcessorTest | ||
void superclassTest() { | ||
SubclassMapper mapper = Mappers.getMapper( SubclassMapper.class ); | ||
Source source = new Source( "f1", "f2", "f3" ); | ||
|
||
Target result = mapper.mapSuperclass( source ); | ||
|
||
Assertions.assertThat( result.getTarget1() ).isEqualTo( "f1" ); | ||
Assertions.assertThat( result.getTarget2() ).isEqualTo( "f2" ); | ||
Assertions.assertThat( result.getTarget3() ).isEqualTo( "f3" ); | ||
Assertions.assertThat( result.getTarget4() ).isNull(); | ||
Assertions.assertThat( result.getTarget5() ).isNull(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
processor/src/test/java/org/mapstruct/ap/test/bugs/_2438/Source.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._2438; | ||
|
||
public class Source { | ||
private String property1; | ||
private String property2; | ||
private String property3; | ||
|
||
public Source(String prop1, String prop2, String prop3) { | ||
setProperty1( prop1 ); | ||
setProperty2( prop2 ); | ||
setProperty3( prop3 ); | ||
} | ||
|
||
public String getProperty1() { | ||
return property1; | ||
} | ||
|
||
public String getProperty2() { | ||
return property2; | ||
} | ||
|
||
public String getProperty3() { | ||
return property3; | ||
} | ||
|
||
public void setProperty1(String property1) { | ||
this.property1 = property1; | ||
} | ||
|
||
public void setProperty2(String property2) { | ||
this.property2 = property2; | ||
} | ||
|
||
public void setProperty3(String property3) { | ||
this.property3 = property3; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
processor/src/test/java/org/mapstruct/ap/test/bugs/_2438/SourceSubclass.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,33 @@ | ||
/* | ||
* 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._2438; | ||
|
||
public class SourceSubclass extends Source { | ||
private String subclassProperty; | ||
private String target5; | ||
|
||
public SourceSubclass(String prop1, String prop2, String prop3, String subProp, String target5) { | ||
super( prop1, prop2, prop3 ); | ||
setSubclassProperty( subProp ); | ||
setTarget5( target5 ); | ||
} | ||
|
||
public String getSubclassProperty() { | ||
return subclassProperty; | ||
} | ||
|
||
public String getTarget5() { | ||
return target5; | ||
} | ||
|
||
public void setSubclassProperty(String subclassProperty) { | ||
this.subclassProperty = subclassProperty; | ||
} | ||
|
||
public void setTarget5(String target5) { | ||
this.target5 = target5; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
processor/src/test/java/org/mapstruct/ap/test/bugs/_2438/SubclassMapper.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._2438; | ||
|
||
import org.mapstruct.InheritConfiguration; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.SubClassMapping; | ||
|
||
@Mapper | ||
public interface SubclassMapper { | ||
|
||
@SubClassMapping( sourceClass = SourceSubclass.class, targetClass = Target.class ) | ||
@Mapping( target = "target1", source = "property1" ) | ||
@Mapping( target = "target2", source = "property2" ) | ||
@Mapping( target = "target3", source = "property3" ) | ||
@Mapping( target = "target4", expression = "java(null)" ) | ||
@Mapping( target = "target5", expression = "java(null)" ) | ||
Target mapSuperclass(Source source); | ||
|
||
@InheritConfiguration( name = "mapSuperclass" ) | ||
@Mapping( target = "target4", source = "subclassProperty" ) | ||
@Mapping( target = "target5" ) // Have to declare in order to override with default behavior | ||
Target mapSubclass(SourceSubclass source); | ||
} |
54 changes: 54 additions & 0 deletions
54
processor/src/test/java/org/mapstruct/ap/test/bugs/_2438/Target.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,54 @@ | ||
/* | ||
* 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._2438; | ||
|
||
public class Target { | ||
private String target1; | ||
private String target2; | ||
private String target3; | ||
private String target4; | ||
private String target5; | ||
|
||
public String getTarget1() { | ||
return target1; | ||
} | ||
|
||
public String getTarget2() { | ||
return target2; | ||
} | ||
|
||
public String getTarget3() { | ||
return target3; | ||
} | ||
|
||
public String getTarget4() { | ||
return target4; | ||
} | ||
|
||
public String getTarget5() { | ||
return target5; | ||
} | ||
|
||
public void setTarget1(String target1) { | ||
this.target1 = target1; | ||
} | ||
|
||
public void setTarget2(String target2) { | ||
this.target2 = target2; | ||
} | ||
|
||
public void setTarget3(String target3) { | ||
this.target3 = target3; | ||
} | ||
|
||
public void setTarget4(String target4) { | ||
this.target4 = target4; | ||
} | ||
|
||
public void setTarget5(String target5) { | ||
this.target5 = target5; | ||
} | ||
} |