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 FailableToDoubleBiFunctionTest extends AbstractLangTest {
33
34 @Test
35 void testApplyAsDouble_returnsResult() throws IOException {
36 final FailableToDoubleBiFunction<String, String, IOException> f = (a, b) -> a.length() + b.length();
37 assertEquals(5.0, f.applyAsDouble("ab", "abc"));
38 }
39
40 @Test
41 void testApplyAsDouble_throwsException() {
42 final IOException expected = new IOException("fail");
43 final FailableToDoubleBiFunction<String, String, IOException> f = (a, b) -> {
44 throw expected;
45 };
46 final IOException thrown = assertThrows(IOException.class, () -> f.applyAsDouble("a", "b"));
47 assertEquals(expected, thrown);
48 }
49
50 @Test
51 void testNop_applyAsDoubleReturnsZero() throws Throwable {
52 assertEquals(0d, FailableToDoubleBiFunction.nop().applyAsDouble("a", "b"));
53 }
54
55 @Test
56 void testNop_returnsNonNull() {
57 assertNotNull(FailableToDoubleBiFunction.nop());
58 }
59 }