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.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26 import java.io.IOException;
27
28 import org.apache.commons.lang3.AbstractLangTest;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34 class FailableToBooleanFunctionTest extends AbstractLangTest {
35
36 @Test
37 void testApplyAsBoolean_returnsTrue() throws IOException {
38 final FailableToBooleanFunction<String, IOException> f = s -> !s.isEmpty();
39 assertTrue(f.applyAsBoolean("hello"));
40 assertFalse(f.applyAsBoolean(""));
41 }
42
43 @Test
44 void testApplyAsBoolean_throwsException() {
45 final IOException expected = new IOException("fail");
46 final FailableToBooleanFunction<String, IOException> f = s -> {
47 throw expected;
48 };
49 final IOException thrown = assertThrows(IOException.class, () -> f.applyAsBoolean("x"));
50 assertEquals(expected, thrown);
51 }
52
53 @Test
54 void testNop_applyAsBooleanReturnsFalse() throws Throwable {
55 assertFalse(FailableToBooleanFunction.nop().applyAsBoolean("x"));
56 }
57
58 @Test
59 void testNop_returnsNonNull() {
60 assertNotNull(FailableToBooleanFunction.nop());
61 }
62 }