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