1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.commons.function;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import org.apache.juneau.*;
22 import org.junit.jupiter.api.*;
23
24 class ThrowingFunction5_Test extends TestBase {
25
26
27
28
29 @Test void a01_basic() {
30 var function = (ThrowingFunction5<String, Integer, Boolean, Double, Long, String>)(a, b, c, d, e) -> {
31 return a + "-" + b + "-" + c + "-" + d + "-" + e;
32 };
33
34 assertEquals("test-42-true-3.14-100", function.apply("test", 42, true, 3.14, 100L));
35 }
36
37 @Test void a02_returnsNull() {
38 ThrowingFunction5<String, Integer, Boolean, Double, Long, String> function = (a, b, c, d, e) -> null;
39
40 assertNull(function.apply("test", 42, true, 3.14, 100L));
41 }
42
43
44
45
46 @Test void b01_throwsCheckedException() {
47 var function = (ThrowingFunction5<String, Integer, Boolean, Double, Long, String>)(a, b, c, d, e) -> {
48 throw new Exception("Test exception");
49 };
50
51 var ex = assertThrows(RuntimeException.class, () -> {
52 function.apply("test", 42, true, 3.14, 100L);
53 });
54
55 assertTrue(ex.getCause() instanceof Exception);
56 assertEquals("Test exception", ex.getCause().getMessage());
57 }
58
59 @Test void b02_throwsRuntimeException() {
60 var function = (ThrowingFunction5<String, Integer, Boolean, Double, Long, String>)(a, b, c, d, e) -> {
61 throw new RuntimeException("Test runtime exception");
62 };
63
64 var ex = assertThrows(RuntimeException.class, () -> {
65 function.apply("test", 42, true, 3.14, 100L);
66 });
67
68 assertEquals("Test runtime exception", ex.getMessage());
69 assertNull(ex.getCause());
70 }
71
72
73
74
75 @Test void c01_usedAsFunction5() {
76 var function = (Function5<String, Integer, Boolean, Double, Long, String>)(a, b, c, d, e) -> a + "-" + b;
77
78 assertEquals("test-42", function.apply("test", 42, true, 3.14, 100L));
79 }
80
81 @Test void c02_lambdaExpression() {
82 ThrowingFunction5<Integer, Integer, Integer, Integer, Integer, Integer> function = (a, b, c, d, e) -> a + b + c + d + e;
83
84 assertEquals(15, function.apply(1, 2, 3, 4, 5));
85 }
86
87 @Test void c03_andThen() {
88 var add = (ThrowingFunction5<Integer, Integer, Integer, Integer, Integer, Integer>)(a, b, c, d, e) -> a + b + c + d + e;
89 var toString = (java.util.function.Function<Integer, String>)Object::toString;
90
91 var composed = add.andThen(toString);
92 assertEquals("15", composed.apply(1, 2, 3, 4, 5));
93 }
94 }
95