|
9 | 9 | import org.springframework.boot.test.mock.mockito.MockBean;
|
10 | 10 | import org.springframework.test.context.junit4.SpringRunner;
|
11 | 11 |
|
| 12 | +import java.util.function.BiFunction; |
| 13 | +import java.util.function.Function; |
| 14 | + |
12 | 15 | import static org.hamcrest.CoreMatchers.equalTo;
|
13 | 16 | import static org.hamcrest.CoreMatchers.is;
|
14 | 17 | import static org.hamcrest.CoreMatchers.notNullValue;
|
@@ -132,4 +135,40 @@ public void getItem_success3() throws Exception {
|
132 | 135 | assertThat("item not equal to id ",id,is(equalTo(res.getId())));
|
133 | 136 |
|
134 | 137 | }
|
| 138 | + |
| 139 | + |
| 140 | + @Test |
| 141 | + public void addMultiple_using_explicitCurry_success(){ |
| 142 | + |
| 143 | + //Arrange |
| 144 | + Function<Integer,Integer> addThree = x-> x+3; |
| 145 | + Function<Integer,Integer> multiplyFour= x-> x*4; |
| 146 | + //method one by more imperative |
| 147 | + Function<Integer, Integer> addThreeThenMuliplyByFour = x-> multiplyFour.apply(addThree.apply(x)); |
| 148 | + //method two more declarative 1 |
| 149 | + Function<Integer,Integer> addThreeThenMuliplyByFourComposition = multiplyFour.compose(addThree); |
| 150 | + //method three more delcartive 2 |
| 151 | + Function<Integer, Integer> addThreeThenMuliplyByFour_andThen = addThree.andThen(multiplyFour); |
| 152 | + |
| 153 | + //Act |
| 154 | + int num = 2; |
| 155 | + int res = |
| 156 | + //addThreeThenMuliplyByFour.apply(2) ; |
| 157 | + //addThreeThenMuliplyByFourComposition.apply(2); |
| 158 | + addThreeThenMuliplyByFour_andThen.apply(num); |
| 159 | + |
| 160 | + //Assert |
| 161 | + // 2+3*4=20 |
| 162 | + assertThat(addThreeThenMuliplyByFour.apply(num), |
| 163 | + is(equalTo(20))); |
| 164 | + assertThat(addThreeThenMuliplyByFourComposition.apply(num), |
| 165 | + is(equalTo(20))); |
| 166 | + assertThat(res, is(equalTo(20))); |
| 167 | + |
| 168 | + |
| 169 | + } |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
135 | 174 | }
|
0 commit comments