-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFileWatcherTest.java
75 lines (63 loc) · 1.63 KB
/
FileWatcherTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.io.util;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* JUnit Test for FileWatcher
*
* @author Omkar Marathe
* @since October 20,2018
*
*/
public class FileWatcherTest {
FileHandlerTest fileHandlerTest;
Thread watcherThread;
Path path;
File file;
private FileWatcher fileWatcher;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
fileHandlerTest = new FileHandlerTest();
path = Paths.get("");
path.toFile().mkdirs();
fileWatcher = new FileWatcher(path, fileHandlerTest,true,StandardWatchEventKinds.ENTRY_CREATE);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
watcherThread = null;
}
@Test(timeout=900)
public void testFileHandler() throws IOException, InterruptedException {
watcherThread = new Thread(fileWatcher);
file = new File("Test.txt");
watcherThread.start();
file.createNewFile();
assertTrue(file.exists());
}
@Test(timeout=900)
public void testFileWatcherStart() throws InterruptedException, IOException {
Thread watcherThread2 = new Thread(fileWatcher);
watcherThread2.start();
Thread.sleep(450);
File file2 = new File("Test1.txt");
file2.createNewFile();
}
@Test(timeout=900)
public void testFileWatcherTestInterrupt() throws InterruptedException {
Thread watcherThread3 = new Thread(fileWatcher);
watcherThread3.start();
watcherThread3.interrupt();
}
}