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 IOQuadFunctionTest {
32
33
34
35
36
37
38 @Test
39 public void testAccept() throws IOException {
40 final AtomicReference<Byte> ref1 = new AtomicReference<>();
41 final AtomicReference<Short> ref2 = new AtomicReference<>();
42 final AtomicReference<String> ref3 = new AtomicReference<>();
43 final AtomicReference<Long> ref4 = new AtomicReference<>();
44 final IOQuadFunction<AtomicReference<Byte>, AtomicReference<Short>, AtomicReference<String>, AtomicReference<Long>, String> quad = (t, u, v, w) -> {
45 ref1.set(Byte.valueOf("1"));
46 ref2.set(Short.valueOf((short) 1));
47 ref3.set("z");
48 ref4.set(Long.valueOf(2));
49 return "ABCD";
50 };
51 assertEquals("ABCD", quad.apply(ref1, ref2, ref3, ref4));
52 assertEquals(Byte.valueOf("1"), ref1.get());
53 assertEquals(Short.valueOf((short) 1), ref2.get());
54 assertEquals("z", ref3.get());
55 assertEquals(Long.valueOf(2), ref4.get());
56 }
57
58
59
60
61
62
63 @Test
64 public void testAndThenIOFunction() throws IOException {
65 final AtomicReference<Byte> ref1 = new AtomicReference<>();
66 final AtomicReference<Short> ref2 = new AtomicReference<>();
67 final AtomicReference<String> ref3 = new AtomicReference<>();
68 final AtomicReference<Long> ref4 = new AtomicReference<>();
69 final IOQuadFunction<AtomicReference<Byte>, AtomicReference<Short>, AtomicReference<String>, AtomicReference<Long>, String> quad = (t, u, v, w) -> {
70 ref1.set(Byte.valueOf("1"));
71 ref2.set(Short.valueOf((short) 1));
72 ref3.set("z");
73 ref4.set(Long.valueOf(2));
74 return "9";
75 };
76 final IOFunction<String, BigInteger> after = t -> {
77 ref1.set(Byte.valueOf("2"));
78 ref2.set(Short.valueOf((short) 2));
79 ref3.set("zz");
80 ref4.set(Long.valueOf(3));
81 return BigInteger.valueOf(Long.parseLong(t)).add(BigInteger.ONE);
82 };
83 assertEquals(BigInteger.TEN, quad.andThen(after).apply(ref1, ref2, ref3, ref4));
84 assertEquals(Byte.valueOf("2"), ref1.get());
85 assertEquals(Short.valueOf((short) 2), ref2.get());
86 assertEquals("zz", ref3.get());
87 assertEquals(Long.valueOf(3), ref4.get());
88 }
89
90 }