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.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.IOException;
25 import java.util.concurrent.atomic.AtomicBoolean;
26
27 import org.apache.commons.lang3.AbstractLangTest;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 class FailableRunnableTest extends AbstractLangTest {
34
35 @Test
36 void testRun_executesBody() throws IOException {
37 final AtomicBoolean ran = new AtomicBoolean();
38 final FailableRunnable<IOException> runnable = () -> ran.set(true);
39 runnable.run();
40 assertTrue(ran.get());
41 }
42
43 @Test
44 void testRun_throwsException() {
45 final IOException expected = new IOException("fail");
46 final FailableRunnable<IOException> runnable = () -> {
47 throw expected;
48 };
49 final IOException thrown = assertThrows(IOException.class, runnable::run);
50 assertEquals(expected, thrown);
51 }
52 }