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.assertNull;
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 FailableSupplierTest extends AbstractLangTest {
33
34 @Test
35 void testGet_returnsValue() throws IOException {
36 final FailableSupplier<String, IOException> supplier = () -> "hello";
37 assertEquals("hello", supplier.get());
38 }
39
40 @Test
41 void testGet_throwsException() {
42 final IOException expected = new IOException("fail");
43 final FailableSupplier<String, IOException> supplier = () -> {
44 throw expected;
45 };
46 final IOException thrown = assertThrows(IOException.class, supplier::get);
47 assertEquals(expected, thrown);
48 }
49
50 @Test
51 void testNULL() throws Throwable {
52 assertNull(FailableSupplier.NUL.get());
53 }
54
55 @Test
56 void testNullSupplierDefaultException() throws Exception {
57 assertNull(FailableSupplier.nul().get());
58 }
59
60 @Test
61 void testNullSupplierException() throws Exception {
62 assertNull(FailableSupplier.<Object, Exception>nul().get());
63 }
64
65 @Test
66 void testNullSupplierRuntimeException() {
67 assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
68 }
69 }