|
1 | 1 | package com.baeldung; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import junit.framework.Assert; |
4 | 5 | import org.jooq.lambda.Seq; |
5 | 6 | import org.jooq.lambda.Unchecked; |
| 7 | +import org.jooq.lambda.function.Function1; |
| 8 | +import org.jooq.lambda.function.Function2; |
| 9 | +import org.jooq.lambda.tuple.Tuple; |
| 10 | +import org.jooq.lambda.tuple.Tuple2; |
| 11 | +import org.jooq.lambda.tuple.Tuple3; |
| 12 | +import org.jooq.lambda.tuple.Tuple4; |
6 | 13 | import org.junit.Test; |
7 | 14 |
|
8 | 15 | import java.util.Arrays; |
@@ -203,4 +210,34 @@ public void givenOperationThatThrowsCheckedException_whenExecuteUsingUncheckedFu |
203 | 210 | ); |
204 | 211 | } |
205 | 212 |
|
| 213 | + @Test |
| 214 | + public void givenFunction_whenAppliedPartially_shouldAddNumberToPartialArgument() { |
| 215 | + //given |
| 216 | + Function2<Integer, Integer, Integer> addTwoNumbers = (v1, v2) -> v1 + v2; |
| 217 | + addTwoNumbers.toBiFunction(); |
| 218 | + Function1<Integer, Integer> addToTwo = addTwoNumbers.applyPartially(2); |
| 219 | + |
| 220 | + //when |
| 221 | + Integer result = addToTwo.apply(5); |
| 222 | + |
| 223 | + //then |
| 224 | + assertEquals(result, (Integer) 7); |
| 225 | + } |
| 226 | + |
| 227 | + @Test |
| 228 | + public void givenSeqOfTuples_whenTransformToLowerNumberOfTuples_shouldHaveProperResult() { |
| 229 | + //given |
| 230 | + Seq<Tuple3<String, String, Integer>> personDetails = Seq.of(tuple("michael", "similar", 49), tuple("jodie", "variable", 43)); |
| 231 | + Tuple2<String, String> tuple = tuple("winter", "summer"); |
| 232 | + |
| 233 | + //when |
| 234 | + List<Tuple4<String, String, String, String>> result = personDetails.map(t -> t.limit2().concat(tuple)).toList(); |
| 235 | + |
| 236 | + //then |
| 237 | + assertEquals( |
| 238 | + result, |
| 239 | + Arrays.asList(tuple("michael", "similar", "winter", "summer"), tuple("jodie", "variable", "winter", "summer")) |
| 240 | + ); |
| 241 | + } |
| 242 | + |
206 | 243 | } |
0 commit comments