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 FailableToIntFunctionTest extends AbstractLangTest {
33
34 @Test
35 void testApplyAsInt_returnsResult() throws IOException {
36 final FailableToIntFunction<String, IOException> f = String::length;
37 assertEquals(5, f.applyAsInt("hello"));
38 }
39
40 @Test
41 void testApplyAsInt_throwsException() {
42 final IOException expected = new IOException("fail");
43 final FailableToIntFunction<String, IOException> f = s -> {
44 throw expected;
45 };
46 final IOException thrown = assertThrows(IOException.class, () -> f.applyAsInt("x"));
47 assertEquals(expected, thrown);
48 }
49
50 @Test
51 void testNop_applyAsIntReturnsZero() throws Throwable {
52 assertEquals(0, FailableToIntFunction.nop().applyAsInt("x"));
53 }
54
55 @Test
56 void testNop_returnsNonNull() {
57 assertNotNull(FailableToIntFunction.nop());
58 }
59 }