1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io;
18
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20
21 import java.util.concurrent.CountDownLatch;
22 import java.util.concurrent.atomic.AtomicBoolean;
23
24 import org.junit.jupiter.api.Test;
25
26
27
28
29
30
31
32
33
34 public class FileUtilsWaitForTest {
35
36 @Test
37 public void testWaitFor0() {
38 FileUtils.waitFor(FileUtils.current(), 0);
39 }
40
41
42
43
44 @Test
45 public void testWaitForInterrupted() throws InterruptedException {
46 final AtomicBoolean wasInterrupted = new AtomicBoolean();
47 final CountDownLatch started = new CountDownLatch(2);
48 final int seconds = 10;
49 final Thread thread1 = new Thread(() -> {
50 started.countDown();
51 assertTrue(FileUtils.waitFor(FileUtils.current(), seconds));
52 wasInterrupted.set(Thread.currentThread().isInterrupted());
53 });
54 thread1.start();
55
56 started.countDown();
57 thread1.interrupt();
58 started.await();
59 thread1.join();
60 assertTrue(wasInterrupted.get());
61 }
62
63 @Test
64 public void testWaitForNegativeDuration() {
65 FileUtils.waitFor(FileUtils.current(), -1);
66 }
67
68 }