Skip to content

Commit d67ace8

Browse files
tomekl007pivovarit
authored andcommitted
BAEL-655 test for partially apllied function (eugenp#1227)
* BAEL-655 test for partially apllied function * BAEL-655 example of tuple transformation
1 parent 355931f commit d67ace8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎jooq/src/test/java/com/baeldung/JOOLTest.java‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package com.baeldung;
22

33

4+
import junit.framework.Assert;
45
import org.jooq.lambda.Seq;
56
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;
613
import org.junit.Test;
714

815
import java.util.Arrays;
@@ -203,4 +210,34 @@ public void givenOperationThatThrowsCheckedException_whenExecuteUsingUncheckedFu
203210
);
204211
}
205212

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+
206243
}

0 commit comments

Comments
 (0)