1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.function;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import java.lang.reflect.Method;
25
26 import org.apache.commons.lang3.exception.CustomCheckedException;
27 import org.apache.commons.lang3.exception.CustomUncheckedException;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class MethodInvokersFailableBiFunctionTest extends MethodFixtures {
34
35 @Test
36 public void testApply1Arg() throws Throwable {
37
38 final FailableBiFunction<MethodFixtures, String, String[], Throwable> func = MethodInvokers.asFailableBiFunction(getMethodForGetString1ArgChecked());
39 assertEquals(INSTANCE.getString1ArgChecked("A"), func.apply(INSTANCE, "A"));
40 }
41
42 @Test
43 public void testApply1ArgThrowsChecked() throws NoSuchMethodException, SecurityException {
44
45 final FailableBiFunction<MethodFixtures, String, String[], Throwable> func = MethodInvokers
46 .asFailableBiFunction(getMethodForGetString1ArgThrowsChecked());
47 assertThrows(CustomCheckedException.class, () -> func.apply(INSTANCE, "A"));
48 }
49
50 @Test
51 public void testApply1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
52
53 final FailableBiFunction<MethodFixtures, String, String[], Throwable> func = MethodInvokers
54 .asFailableBiFunction(getMethodForGetString1ArgThrowsUnchecked());
55 assertThrows(CustomUncheckedException.class, () -> func.apply(INSTANCE, "A"));
56 }
57
58 @Test
59 public void testConstructorForNull() throws SecurityException {
60 assertThrows(NullPointerException.class, () -> MethodInvokers.asFailableBiFunction(null));
61 }
62
63 @Test
64 public void testToString() throws SecurityException, Throwable {
65
66 assertFalse(MethodInvokers.asFailableBiFunction(getMethodForGetString1ArgChecked()).toString().isEmpty());
67 }
68
69 }