-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added DefaultBeanInitializer#mapParameterizedArguments(Type[], Object[]), allowing BeanMapper to properly map constructor parameters with a type-parameter, when using the @BeanConstruct-annotation. - Using @sptdevos' tests to confirm proper functionality. - Updated CHANGELOG.md
- Loading branch information
1 parent
4b7af33
commit 7d3ca40
Showing
9 changed files
with
129 additions
and
4 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
31 changes: 31 additions & 0 deletions
31
src/test/java/io/beanmapper/annotations/BeanConstructTest.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,31 @@ | ||
package io.beanmapper.annotations; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import io.beanmapper.annotations.model.bean_construct.NestedSource; | ||
import io.beanmapper.annotations.model.bean_construct.Source; | ||
import io.beanmapper.annotations.model.bean_construct.Target; | ||
import io.beanmapper.config.BeanMapperBuilder; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class BeanConstructTest { | ||
|
||
@Test | ||
void beanConstruct_shouldUse_argsConstructor() { | ||
NestedSource nestedSource = new NestedSource(); | ||
nestedSource.nestedField = 42; | ||
|
||
Source source = new Source(); | ||
source.field1 = 40; | ||
source.field2 = 41; | ||
source.nested = List.of(nestedSource); | ||
|
||
Target target = new BeanMapperBuilder().build().map(source, Target.class); | ||
assertEquals(Integer.valueOf(40), target.getField1()); | ||
assertEquals(Integer.valueOf(41), target.getField2()); | ||
assertEquals(Integer.valueOf(42), target.getNested().get(0).getNestedField()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/java/io/beanmapper/annotations/model/bean_construct/NestedSource.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,5 @@ | ||
package io.beanmapper.annotations.model.bean_construct; | ||
|
||
public class NestedSource { | ||
public Integer nestedField; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/io/beanmapper/annotations/model/bean_construct/NestedTarget.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,14 @@ | ||
package io.beanmapper.annotations.model.bean_construct; | ||
|
||
public class NestedTarget { | ||
|
||
private Integer nestedField; | ||
|
||
public Integer getNestedField() { | ||
return nestedField; | ||
} | ||
|
||
public void setNestedField(Integer nestedField) { | ||
this.nestedField = nestedField; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/java/io/beanmapper/annotations/model/bean_construct/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,9 @@ | ||
package io.beanmapper.annotations.model.bean_construct; | ||
|
||
import java.util.List; | ||
|
||
public class Source { | ||
public Integer field1; | ||
public Integer field2; | ||
public List<NestedSource> nested; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/io/beanmapper/annotations/model/bean_construct/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,31 @@ | ||
package io.beanmapper.annotations.model.bean_construct; | ||
|
||
import java.util.List; | ||
|
||
import io.beanmapper.annotations.BeanConstruct; | ||
|
||
@BeanConstruct({ "field1", "field2", "nested" }) | ||
public class Target { | ||
private final Integer field1; | ||
private final Integer field2; | ||
private final List<NestedTarget> nested; | ||
|
||
public Target(Integer field1, Integer field2, List<NestedTarget> nested) { | ||
this.field1 = field1; | ||
this.field2 = field2; | ||
this.nested = nested; | ||
} | ||
|
||
public Integer getField1() { | ||
return field1; | ||
} | ||
|
||
public Integer getField2() { | ||
return field2; | ||
} | ||
|
||
public List<NestedTarget> getNested() { | ||
return nested; | ||
} | ||
|
||
} |
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
4 changes: 4 additions & 0 deletions
4
src/test/java/io/beanmapper/core/constructor/DefaultBeanInitializerTest.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,4 @@ | ||
package io.beanmapper.core.constructor; | ||
|
||
public class DefaultBeanInitializerTest { | ||
} |