1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io.function;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import java.io.IOException;
23 import java.math.BigInteger;
24 import java.util.concurrent.atomic.AtomicReference;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 public class IOTriFunctionTest {
32
33
34
35
36
37
38 @Test
39 public void testAccept() throws IOException {
40 final AtomicReference<Character> ref1 = new AtomicReference<>();
41 final AtomicReference<Short> ref2 = new AtomicReference<>();
42 final AtomicReference<String> ref3 = new AtomicReference<>();
43 final IOTriFunction<AtomicReference<Character>, AtomicReference<Short>, AtomicReference<String>, String> tri = (t, u, v) -> {
44 ref1.set(Character.valueOf('a'));
45 ref2.set(Short.valueOf((short) 1));
46 ref3.set("z");
47 return "ABC";
48 };
49 assertEquals("ABC", tri.apply(ref1, ref2, ref3));
50 assertEquals(Character.valueOf('a'), ref1.get());
51 assertEquals(Short.valueOf((short) 1), ref2.get());
52 assertEquals("z", ref3.get());
53 }
54
55
56
57
58
59
60 @Test
61 public void testAndThenIOFunction() throws IOException {
62 final AtomicReference<Character> ref1 = new AtomicReference<>();
63 final AtomicReference<Short> ref2 = new AtomicReference<>();
64 final AtomicReference<String> ref3 = new AtomicReference<>();
65 final IOTriFunction<AtomicReference<Character>, AtomicReference<Short>, AtomicReference<String>, String> tri = (t, u, v) -> {
66 ref1.set(Character.valueOf('a'));
67 ref2.set(Short.valueOf((short) 1));
68 ref3.set("z");
69 return "9";
70 };
71 final IOFunction<String, BigInteger> after = t -> {
72 ref1.set(Character.valueOf('b'));
73 ref2.set(Short.valueOf((short) 2));
74 ref3.set("zz");
75 return BigInteger.valueOf(Long.parseLong(t)).add(BigInteger.ONE);
76 };
77 assertEquals(BigInteger.TEN, tri.andThen(after).apply(ref1, ref2, ref3));
78 assertEquals(Character.valueOf('b'), ref1.get());
79 assertEquals(Short.valueOf((short) 2), ref2.get());
80 assertEquals("zz", ref3.get());
81 }
82
83 }