forked from remondis-it/remap
-
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.
Proof of concept allowing chained setters.
- Loading branch information
Showing
4 changed files
with
134 additions
and
3 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
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,56 @@ | ||
package com.remondis.remap.fluent; | ||
|
||
public class A { | ||
|
||
private Integer integer; | ||
private int i; | ||
private String s; | ||
private boolean b1; | ||
private boolean b2; | ||
|
||
public Integer getInteger() { | ||
return integer; | ||
} | ||
|
||
public A setInteger(Integer integer) { | ||
this.integer = integer; | ||
return this; | ||
} | ||
|
||
public int getI() { | ||
return integer; | ||
} | ||
|
||
public A setI(int i) { | ||
this.i = i; | ||
return this; | ||
} | ||
|
||
public String getS() { | ||
return s; | ||
} | ||
|
||
public A setS(String s) { | ||
this.s = s; | ||
return this; | ||
} | ||
|
||
public boolean getB1() { | ||
return b1; | ||
} | ||
|
||
public A setB1(boolean b) { | ||
this.b1 = b; | ||
return this; | ||
} | ||
|
||
public boolean isB2() { | ||
return b2; | ||
} | ||
|
||
public A setB2(boolean b) { | ||
this.b2 = b; | ||
return this; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/remondis/remap/fluent/ChainedSetterTest.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,34 @@ | ||
package com.remondis.remap.fluent; | ||
|
||
import com.remondis.remap.Mapper; | ||
import com.remondis.remap.Mapping; | ||
import com.remondis.remap.MappingException; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ChainedSetterTest { | ||
|
||
@Test | ||
public void testChainedSetter() { | ||
Mapper<A, A> m = Mapping.from(A.class) | ||
.to(A.class) | ||
.allowFluentSetters(true) | ||
.mapper(); | ||
A expected = new A().setInteger(5) | ||
.setI(22) | ||
.setS("str") | ||
.setB1(true) | ||
.setB2(true); | ||
A actual = m.map(expected); | ||
assertThat(actual).isEqualToComparingFieldByField(expected); | ||
} | ||
|
||
@Test(expected = MappingException.class) | ||
public void checkConfigurationOfChainedSetters() { | ||
Mapping.from(A.class) | ||
.to(A.class) | ||
.mapper(); | ||
} | ||
|
||
} |