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#3667, mapstruct#3673 MappingReference should custom Mapping…
…Option equality instead of the default only target name based one
- Loading branch information
Showing
12 changed files
with
399 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
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Mapper.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,22 @@ | ||
/* | ||
* 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._3667; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface Issue3667Mapper { | ||
|
||
Issue3667Mapper INSTANCE = Mappers.getMapper( Issue3667Mapper.class ); | ||
|
||
@Mapping(target = "nested.value", source = "nested.nested1.value") | ||
Target mapFirst(Source source); | ||
|
||
@Mapping(target = "nested.value", source = "nested.nested2.value") | ||
Target mapSecond(Source source); | ||
} |
43 changes: 43 additions & 0 deletions
43
processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Test.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,43 @@ | ||
/* | ||
* 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._3667; | ||
|
||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.ProcessorTest; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@IssueKey("3667") | ||
@WithClasses({ | ||
Issue3667Mapper.class, | ||
Source.class, | ||
Target.class | ||
}) | ||
class Issue3667Test { | ||
|
||
@ProcessorTest | ||
void shouldCorrectlyMapNestedProperty() { | ||
Source source = new Source( | ||
new Source.Nested( | ||
new Source.NestedNested( "value1" ), | ||
new Source.NestedNested( "value2" ) | ||
) | ||
); | ||
|
||
Target target1 = Issue3667Mapper.INSTANCE.mapFirst( source ); | ||
Target target2 = Issue3667Mapper.INSTANCE.mapSecond( source ); | ||
|
||
assertThat( target1 ).isNotNull(); | ||
assertThat( target1.getNested() ).isNotNull(); | ||
assertThat( target1.getNested().getValue() ).isEqualTo( "value1" ); | ||
|
||
assertThat( target2 ).isNotNull(); | ||
assertThat( target2.getNested() ).isNotNull(); | ||
assertThat( target2.getNested().getValue() ).isEqualTo( "value2" ); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/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,51 @@ | ||
/* | ||
* 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._3667; | ||
|
||
public class Source { | ||
|
||
private final Nested nested; | ||
|
||
public Source(Nested nested) { | ||
this.nested = nested; | ||
} | ||
|
||
public Nested getNested() { | ||
return nested; | ||
} | ||
|
||
public static class Nested { | ||
|
||
private final NestedNested nested1; | ||
private final NestedNested nested2; | ||
|
||
public Nested(NestedNested nested1, NestedNested nested2) { | ||
this.nested1 = nested1; | ||
this.nested2 = nested2; | ||
} | ||
|
||
public NestedNested getNested1() { | ||
return nested1; | ||
} | ||
|
||
public NestedNested getNested2() { | ||
return nested2; | ||
} | ||
} | ||
|
||
public static class NestedNested { | ||
|
||
private final String value; | ||
|
||
public NestedNested(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/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,32 @@ | ||
/* | ||
* 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._3667; | ||
|
||
public class Target { | ||
|
||
private Nested nested; | ||
|
||
public Nested getNested() { | ||
return nested; | ||
} | ||
|
||
public void setNested(Nested nested) { | ||
this.nested = nested; | ||
} | ||
|
||
public static class Nested { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Animal.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._3673; | ||
|
||
public class Animal { | ||
|
||
private AnimalDetails details; | ||
|
||
public AnimalDetails getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(AnimalDetails details) { | ||
this.details = details; | ||
} | ||
|
||
public enum Type { | ||
CAT, | ||
DOG | ||
} | ||
|
||
public static class AnimalDetails { | ||
private Type type; | ||
private String name; | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public void setType(Type type) { | ||
this.type = type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Cat.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,19 @@ | ||
/* | ||
* 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._3673; | ||
|
||
public class Cat { | ||
|
||
private final Details details; | ||
|
||
public Cat(Details details) { | ||
this.details = details; | ||
} | ||
|
||
public Details getDetails() { | ||
return details; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Details.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,19 @@ | ||
/* | ||
* 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._3673; | ||
|
||
public class Details { | ||
|
||
private final String name; | ||
|
||
public Details(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Dog.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,19 @@ | ||
/* | ||
* 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._3673; | ||
|
||
public class Dog { | ||
|
||
private final Details details; | ||
|
||
public Dog(Details details) { | ||
this.details = details; | ||
} | ||
|
||
public Details getDetails() { | ||
return details; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ConstantMapper.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,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.bugs._3673; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface Issue3673ConstantMapper { | ||
|
||
Issue3673ConstantMapper INSTANCE = Mappers.getMapper( Issue3673ConstantMapper.class ); | ||
|
||
@Mapping(target = "details.name", source = "details.name") | ||
@Mapping(target = "details.type", constant = "DOG") | ||
Animal map(Dog dog); | ||
|
||
@Mapping(target = "details.name", source = "details.name") | ||
@Mapping(target = "details.type", constant = "CAT") | ||
Animal map(Cat cat); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ExpressionMapper.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,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.bugs._3673; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface Issue3673ExpressionMapper { | ||
|
||
Issue3673ExpressionMapper INSTANCE = Mappers.getMapper( Issue3673ExpressionMapper.class ); | ||
|
||
@Mapping(target = "details.name", source = "details.name") | ||
@Mapping(target = "details.type", expression = "java(Animal.Type.DOG)") | ||
Animal map(Dog dog); | ||
|
||
@Mapping(target = "details.name", source = "details.name") | ||
@Mapping(target = "details.type", expression = "java(Animal.Type.CAT)") | ||
Animal map(Cat cat); | ||
|
||
} |
Oops, something went wrong.