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.apache.commons.lang3.LangAssertions.assertNullPointerException;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
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 FailableDoubleUnaryOperatorTest extends AbstractLangTest {
34
35 @Test
36 void testAndThen_composesCorrectly() throws IOException {
37 final FailableDoubleUnaryOperator<IOException> times2 = v -> v * 2;
38 final FailableDoubleUnaryOperator<IOException> plus1 = v -> v + 1;
39 assertEquals(7.0, times2.andThen(plus1).applyAsDouble(3.0));
40 }
41
42 @Test
43 void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
44 final FailableDoubleUnaryOperator<IOException> op = v -> v;
45 assertNullPointerException(() -> op.andThen(null));
46 }
47
48 @Test
49 void testApplyAsDouble_returnsResult() throws IOException {
50 final FailableDoubleUnaryOperator<IOException> op = v -> v * 2;
51 assertEquals(6.0, op.applyAsDouble(3.0));
52 }
53
54 @Test
55 void testApplyAsDouble_throwsException() {
56 final IOException expected = new IOException("fail");
57 final FailableDoubleUnaryOperator<IOException> op = v -> {
58 throw expected;
59 };
60 final IOException thrown = assertThrows(IOException.class, () -> op.applyAsDouble(1.0));
61 assertEquals(expected, thrown);
62 }
63
64 @Test
65 void testCompose_composesCorrectly() throws IOException {
66 final FailableDoubleUnaryOperator<IOException> times2 = v -> v * 2;
67 final FailableDoubleUnaryOperator<IOException> plus1 = v -> v + 1;
68 assertEquals(8.0, times2.compose(plus1).applyAsDouble(3.0));
69 }
70
71 @Test
72 void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
73 final FailableDoubleUnaryOperator<IOException> op = v -> v;
74 assertNullPointerException(() -> op.compose(null));
75 }
76
77 @Test
78 void testIdentity_returnsInput() throws IOException {
79 assertEquals(3.14, FailableDoubleUnaryOperator.<IOException>identity().applyAsDouble(3.14));
80 }
81
82 @Test
83 void testNop_applyAsDoubleReturnsZero() throws Throwable {
84 assertEquals(0d, FailableDoubleUnaryOperator.nop().applyAsDouble(5.0));
85 }
86
87 @Test
88 void testNop_returnsNonNull() {
89 assertNotNull(FailableDoubleUnaryOperator.nop());
90 }
91 }