1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * https://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */1718package org.apache.commons.lang3.function;
1920importstatic org.junit.jupiter.api.Assertions.assertEquals;
2122import java.math.BigInteger;
23import java.util.concurrent.atomic.AtomicReference;
24import java.util.function.Function;
2526import org.apache.commons.lang3.AbstractLangTest;
27import org.junit.jupiter.api.Test;
2829/**30 * Tests {@link TriFunction}.31 */32classTriFunctionTestextendsAbstractLangTest {
3334 @Test
35void testAccept() throws Throwable {
36final AtomicReference<Character> ref1 = new AtomicReference<>();
37final AtomicReference<Short> ref2 = new AtomicReference<>();
38final AtomicReference<String> ref3 = new AtomicReference<>();
39final TriFunction<AtomicReference<Character>, AtomicReference<Short>, AtomicReference<String>, String> tri = (t, u, v) -> {
40 ref1.set(Character.valueOf('a'));
41 ref2.set(Short.valueOf((short) 1));
42 ref3.set("z");
43return"ABC";
44 };
45 assertEquals("ABC", tri.apply(ref1, ref2, ref3));
46 assertEquals(Character.valueOf('a'), ref1.get());
47 assertEquals(Short.valueOf((short) 1), ref2.get());
48 assertEquals("z", ref3.get());
49 }
5051 @Test
52void testAndThen() throws Throwable {
53final AtomicReference<Character> ref1 = new AtomicReference<>();
54final AtomicReference<Short> ref2 = new AtomicReference<>();
55final AtomicReference<String> ref3 = new AtomicReference<>();
56final TriFunction<AtomicReference<Character>, AtomicReference<Short>, AtomicReference<String>, String> tri = (t, u, v) -> {
57 ref1.set(Character.valueOf('a'));
58 ref2.set(Short.valueOf((short) 1));
59 ref3.set("z");
60return"9";
61 };
62final Function<String, BigInteger> after = t -> {
63 ref1.set(Character.valueOf('b'));
64 ref2.set(Short.valueOf((short) 2));
65 ref3.set("zz");
66return BigInteger.valueOf(Long.parseLong(t)).add(BigInteger.ONE);
67 };
68 assertEquals(BigInteger.TEN, tri.andThen(after).apply(ref1, ref2, ref3));
69 assertEquals(Character.valueOf('b'), ref1.get());
70 assertEquals(Short.valueOf((short) 2), ref2.get());
71 assertEquals("zz", ref3.get());
72 }
7374 }