-
-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1828 Use update method when nested property of target is populated w…
…ith multiple nested properties of source (#1930)
- Loading branch information
Showing
8 changed files
with
301 additions
and
2 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
46 changes: 46 additions & 0 deletions
46
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/CompleteAddress.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,46 @@ | ||
/* | ||
* 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._1828; | ||
|
||
public class CompleteAddress { | ||
|
||
private String lineOne; | ||
private String lineTwo; | ||
private String city; | ||
private String country; | ||
|
||
public String getLineOne() { | ||
return lineOne; | ||
} | ||
|
||
public void setLineOne(String lineOne) { | ||
this.lineOne = lineOne; | ||
} | ||
|
||
public String getLineTwo() { | ||
return lineTwo; | ||
} | ||
|
||
public void setLineTwo(String lineTwo) { | ||
this.lineTwo = lineTwo; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Employee.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,37 @@ | ||
/* | ||
* 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._1828; | ||
|
||
public class Employee { | ||
|
||
private String name; | ||
private GeneralAddress generalAddress; | ||
private SpecialAddress specialAddress; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public GeneralAddress getGeneralAddress() { | ||
return generalAddress; | ||
} | ||
|
||
public void setGeneralAddress(GeneralAddress generalAddress) { | ||
this.generalAddress = generalAddress; | ||
} | ||
|
||
public SpecialAddress getSpecialAddress() { | ||
return specialAddress; | ||
} | ||
|
||
public void setSpecialAddress(SpecialAddress specialAddress) { | ||
this.specialAddress = specialAddress; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/FirstMapper.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,23 @@ | ||
/* | ||
* 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._1828; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface FirstMapper { | ||
|
||
FirstMapper INSTANCE = Mappers.getMapper( FirstMapper.class ); | ||
|
||
@Mapping(target = "completeAddress.lineOne", source = "specialAddress.line1") | ||
@Mapping(target = "completeAddress.lineTwo", source = "specialAddress.line2") | ||
@Mapping(target = "completeAddress.city", source = "generalAddress.city") | ||
@Mapping(target = "completeAddress.country", source = "generalAddress.country") | ||
Person mapPerson(Employee employee); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/GeneralAddress.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._1828; | ||
|
||
public class GeneralAddress { | ||
|
||
private String city; | ||
private String country; | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Issue1828Test.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,101 @@ | ||
/* | ||
* 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._1828; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@IssueKey("1828") | ||
@RunWith(AnnotationProcessorTestRunner.class) | ||
@WithClasses({ | ||
CompleteAddress.class, | ||
Employee.class, | ||
FirstMapper.class, | ||
GeneralAddress.class, | ||
Person.class, | ||
SpecialAddress.class, | ||
}) | ||
public class Issue1828Test { | ||
|
||
@Test | ||
public void testMapSpecialAndGeneralAddressSet() { | ||
|
||
Employee employee = new Employee(); | ||
employee.setName( "Mad King" ); | ||
|
||
SpecialAddress specialAddress = new SpecialAddress(); | ||
specialAddress.setLine1( "Building One" ); | ||
specialAddress.setLine2( "Street Two" ); | ||
employee.setSpecialAddress( specialAddress ); | ||
|
||
GeneralAddress generalAddress = new GeneralAddress(); | ||
generalAddress.setCity( "King's Landing" ); | ||
generalAddress.setCountry( "Seven Kingdom" ); | ||
employee.setGeneralAddress( generalAddress ); | ||
|
||
Person person = FirstMapper.INSTANCE.mapPerson( employee ); | ||
assertThat( person.getName() ).isEqualTo( "Mad King" ); | ||
|
||
CompleteAddress completeAddress = person.getCompleteAddress(); | ||
assertThat( completeAddress ).isNotNull(); | ||
assertThat( completeAddress.getLineOne() ).isEqualTo( "Building One" ); | ||
assertThat( completeAddress.getLineTwo() ).isEqualTo( "Street Two" ); | ||
assertThat( completeAddress.getCity() ).isEqualTo( "King's Landing" ); | ||
assertThat( completeAddress.getCountry() ).isEqualTo( "Seven Kingdom" ); | ||
} | ||
|
||
@Test | ||
public void testMapGeneralAddressNull() { | ||
|
||
Employee employee = new Employee(); | ||
employee.setName( "Mad King" ); | ||
|
||
SpecialAddress specialAddress = new SpecialAddress(); | ||
specialAddress.setLine1( "Building One" ); | ||
specialAddress.setLine2( "Street Two" ); | ||
employee.setSpecialAddress( specialAddress ); | ||
|
||
Person person = FirstMapper.INSTANCE.mapPerson( employee ); | ||
assertThat( person.getName() ).isEqualTo( "Mad King" ); | ||
|
||
CompleteAddress completeAddress = person.getCompleteAddress(); | ||
assertThat( completeAddress ).isNotNull(); | ||
assertThat( completeAddress.getLineOne() ).isEqualTo( "Building One" ); | ||
assertThat( completeAddress.getLineTwo() ).isEqualTo( "Street Two" ); | ||
assertThat( completeAddress.getCity() ).isNull(); | ||
assertThat( completeAddress.getCountry() ).isNull(); | ||
} | ||
|
||
@Test | ||
public void testMapSpecialAddressNull() { | ||
|
||
Employee employee = new Employee(); | ||
employee.setName( "Mad King" ); | ||
|
||
GeneralAddress generalAddress = new GeneralAddress(); | ||
generalAddress.setCity( "King's Landing" ); | ||
generalAddress.setCountry( "Seven Kingdom" ); | ||
employee.setGeneralAddress( generalAddress ); | ||
|
||
Person person = FirstMapper.INSTANCE.mapPerson( employee ); | ||
assertThat( person.getName() ).isEqualTo( "Mad King" ); | ||
|
||
CompleteAddress completeAddress = person.getCompleteAddress(); | ||
assertThat( completeAddress ).isNotNull(); | ||
assertThat( completeAddress.getLineOne() ).isNull(); | ||
assertThat( completeAddress.getLineTwo() ).isNull(); | ||
assertThat( completeAddress.getCity() ).isEqualTo( "King's Landing" ); | ||
assertThat( completeAddress.getCountry() ).isEqualTo( "Seven Kingdom" ); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Person.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._1828; | ||
|
||
public class Person { | ||
|
||
String name; | ||
private CompleteAddress completeAddress; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public CompleteAddress getCompleteAddress() { | ||
return completeAddress; | ||
} | ||
|
||
public void setCompleteAddress(CompleteAddress completeAddress) { | ||
this.completeAddress = completeAddress; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/SpecialAddress.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._1828; | ||
|
||
public class SpecialAddress { | ||
|
||
private String line1; | ||
private String line2; | ||
|
||
public String getLine1() { | ||
return line1; | ||
} | ||
|
||
public void setLine1(String line1) { | ||
this.line1 = line1; | ||
} | ||
|
||
public String getLine2() { | ||
return line2; | ||
} | ||
|
||
public void setLine2(String line2) { | ||
this.line2 = line2; | ||
} | ||
} |