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 FailableLongUnaryOperatorTest extends AbstractLangTest {
34
35 @Test
36 void testAndThen_composesCorrectly() throws IOException {
37 final FailableLongUnaryOperator<IOException> times2 = v -> v * 2;
38 final FailableLongUnaryOperator<IOException> plus1 = v -> v + 1;
39 assertEquals(7L, times2.andThen(plus1).applyAsLong(3L));
40 }
41
42 @Test
43 void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
44 final FailableLongUnaryOperator<IOException> op = v -> v;
45 assertNullPointerException(() -> op.andThen(null));
46 }
47
48 @Test
49 void testApplyAsLong_returnsResult() throws IOException {
50 final FailableLongUnaryOperator<IOException> op = v -> v * 2;
51 assertEquals(10L, op.applyAsLong(5L));
52 }
53
54 @Test
55 void testApplyAsLong_throwsException() {
56 final IOException expected = new IOException("fail");
57 final FailableLongUnaryOperator<IOException> op = v -> {
58 throw expected;
59 };
60 final IOException thrown = assertThrows(IOException.class, () -> op.applyAsLong(1L));
61 assertEquals(expected, thrown);
62 }
63
64 @Test
65 void testCompose_composesCorrectly() throws IOException {
66 final FailableLongUnaryOperator<IOException> times2 = v -> v * 2;
67 final FailableLongUnaryOperator<IOException> plus1 = v -> v + 1;
68 assertEquals(8L, times2.compose(plus1).applyAsLong(3L));
69 }
70
71 @Test
72 void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
73 final FailableLongUnaryOperator<IOException> op = v -> v;
74 assertNullPointerException(() -> op.compose(null));
75 }
76
77 @Test
78 void testIdentity_returnsInput() throws IOException {
79 assertEquals(7L, FailableLongUnaryOperator.<IOException>identity().applyAsLong(7L));
80 }
81
82 @Test
83 void testNop_applyAsLongReturnsZero() throws Throwable {
84 assertEquals(0L, FailableLongUnaryOperator.nop().applyAsLong(5L));
85 }
86
87 @Test
88 void testNop_returnsNonNull() {
89 assertNotNull(FailableLongUnaryOperator.nop());
90 }
91 }