From d67ace8e1e45a3b301a7358ae726f371468381dd Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Fri, 24 Feb 2017 16:19:28 +0100 Subject: [PATCH] BAEL-655 test for partially apllied function (#1227) * BAEL-655 test for partially apllied function * BAEL-655 example of tuple transformation --- jooq/src/test/java/com/baeldung/JOOLTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/jooq/src/test/java/com/baeldung/JOOLTest.java b/jooq/src/test/java/com/baeldung/JOOLTest.java index 18fca1f67a..13bf1a3ec3 100644 --- a/jooq/src/test/java/com/baeldung/JOOLTest.java +++ b/jooq/src/test/java/com/baeldung/JOOLTest.java @@ -1,8 +1,15 @@ package com.baeldung; +import junit.framework.Assert; import org.jooq.lambda.Seq; import org.jooq.lambda.Unchecked; +import org.jooq.lambda.function.Function1; +import org.jooq.lambda.function.Function2; +import org.jooq.lambda.tuple.Tuple; +import org.jooq.lambda.tuple.Tuple2; +import org.jooq.lambda.tuple.Tuple3; +import org.jooq.lambda.tuple.Tuple4; import org.junit.Test; import java.util.Arrays; @@ -203,4 +210,34 @@ public class JOOLTest { ); } + @Test + public void givenFunction_whenAppliedPartially_shouldAddNumberToPartialArgument() { + //given + Function2 addTwoNumbers = (v1, v2) -> v1 + v2; + addTwoNumbers.toBiFunction(); + Function1 addToTwo = addTwoNumbers.applyPartially(2); + + //when + Integer result = addToTwo.apply(5); + + //then + assertEquals(result, (Integer) 7); + } + + @Test + public void givenSeqOfTuples_whenTransformToLowerNumberOfTuples_shouldHaveProperResult() { + //given + Seq> personDetails = Seq.of(tuple("michael", "similar", 49), tuple("jodie", "variable", 43)); + Tuple2 tuple = tuple("winter", "summer"); + + //when + List> result = personDetails.map(t -> t.limit2().concat(tuple)).toList(); + + //then + assertEquals( + result, + Arrays.asList(tuple("michael", "similar", "winter", "summer"), tuple("jodie", "variable", "winter", "summer")) + ); + } + }