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.assertThrows;
23
24 import java.io.IOException;
25
26 import org.apache.commons.lang3.AbstractLangTest;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 class FailableToDoubleFunctionTest extends AbstractLangTest {
33
34 @Test
35 void testApplyAsDouble_returnsResult() throws IOException {
36 final FailableToDoubleFunction<String, IOException> f = s -> s.length() * 1.5;
37 assertEquals(7.5, f.applyAsDouble("hello"));
38 }
39
40 @Test
41 void testApplyAsDouble_throwsException() {
42 final IOException expected = new IOException("fail");
43 final FailableToDoubleFunction<String, IOException> f = s -> {
44 throw expected;
45 };
46 final IOException thrown = assertThrows(IOException.class, () -> f.applyAsDouble("x"));
47 assertEquals(expected, thrown);
48 }
49
50 @Test
51 void testNop_applyAsDoubleReturnsZero() throws Throwable {
52 assertEquals(0d, FailableToDoubleFunction.nop().applyAsDouble("x"));
53 }
54
55 @Test
56 void testNop_returnsNonNull() {
57 assertNotNull(FailableToDoubleFunction.nop());
58 }
59 }