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.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24
25 import java.io.IOException;
26
27 import org.apache.commons.lang3.AbstractLangTest;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 class FailableDoubleFunctionTest extends AbstractLangTest {
34
35 @Test
36 void testApply_returnsResult() throws IOException {
37 final FailableDoubleFunction<String, IOException> f = v -> "v=" + v;
38 assertEquals("v=2.5", f.apply(2.5));
39 }
40
41 @Test
42 void testApply_throwsException() {
43 final IOException expected = new IOException("fail");
44 final FailableDoubleFunction<String, IOException> f = v -> {
45 throw expected;
46 };
47 final IOException thrown = assertThrows(IOException.class, () -> f.apply(1.0));
48 assertEquals(expected, thrown);
49 }
50
51 @Test
52 void testNop_applyReturnsNull() throws Throwable {
53 assertNull(FailableDoubleFunction.nop().apply(1.0));
54 }
55
56 @Test
57 void testNop_returnsNonNull() {
58 assertNotNull(FailableDoubleFunction.nop());
59 }
60 }