1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io.function;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.IOException;
25 import java.util.concurrent.atomic.AtomicBoolean;
26 import java.util.concurrent.atomic.AtomicInteger;
27
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 final class EraseTest {
34
35 private final AtomicInteger intRef = new AtomicInteger();
36 private final AtomicBoolean boolRef = new AtomicBoolean();
37
38 @Test
39 void testAcceptIOBiConsumerOfTUTU() {
40 Erase.accept((e, f) -> boolRef.set(intRef.compareAndSet(0, e)), 1, true);
41 assertEquals(1, intRef.get());
42 assertTrue(boolRef.get());
43 assertThrows(IOException.class, () -> Erase.accept(TestUtils.throwingIOBiConsumer(), null, 1));
44 }
45
46 @Test
47 void testAcceptIOConsumerOfTT() {
48 Erase.accept(e -> intRef.compareAndSet(0, e), 1);
49 assertEquals(1, intRef.get());
50 assertThrows(IOException.class, () -> Erase.accept(TestUtils.throwingIOConsumer(), 1));
51 }
52
53 @Test
54 void testApplyIOBiFunctionOfQsuperTQsuperUQextendsRTU() {
55 assertTrue(Erase.<Integer, Boolean, Boolean>apply((i, b) -> boolRef.compareAndSet(false, intRef.compareAndSet(0, i.intValue())), 1, Boolean.TRUE));
56 assertThrows(IOException.class, () -> Erase.apply(TestUtils.throwingIOBiFunction(), 1, Boolean.TRUE));
57 }
58
59 @Test
60 void testApplyIOFunctionOfQsuperTQextendsRT() {
61 assertTrue(Erase.<Integer, Boolean>apply(e -> intRef.compareAndSet(0, e), 1));
62 assertThrows(IOException.class, () -> Erase.apply(TestUtils.throwingIOFunction(), 1));
63 }
64
65 @Test
66 void testCompare() {
67 assertEquals(0, Erase.compare(String::compareTo, "A", "A"));
68 assertEquals(-1, Erase.compare(String::compareTo, "A", "B"));
69 assertEquals(1, Erase.compare(String::compareTo, "B", "A"));
70 assertThrows(IOException.class, () -> Erase.compare(TestUtils.throwingIOComparator(), null, null));
71 }
72
73 @Test
74 void testGet() {
75 assertEquals(0, Erase.get(() -> intRef.get()));
76 assertThrows(IOException.class, () -> Erase.get(TestUtils.throwingIOSupplier()));
77 }
78
79 @Test
80 void testRethrow() {
81 assertThrows(IOException.class, () -> Erase.rethrow(new IOException()));
82 }
83
84 @Test
85 void testRun() {
86 Erase.run(() -> intRef.set(1));
87 assertEquals(1, intRef.get());
88 assertThrows(IOException.class, () -> Erase.run(TestUtils.throwingIORunnable()));
89 }
90
91 @Test
92 void testTest() {
93 assertTrue(Erase.test(e -> intRef.compareAndSet(0, e), 1));
94 assertThrows(IOException.class, () -> Erase.test(TestUtils.throwingIOPredicate(), 1));
95 }
96
97 }