/** Create a folder, watch it then put a couple of files in and check they are detected */ @Ignore @Test public void dirs() throws IOException { TestFileChangeListener listener = new TestFileChangeListener(); File dir = getTempDir(); FileSystemWatcher watcher = new FileSystemWatcher(listener, -1, "test"); watcher.register(dir); pause(1000); create(dir, "abc.txt"); pause(1100); create(dir, "abcd.txt"); pause(1100); watcher.shutdown(); Assert.assertTrue(listener.changesDetected.contains("abc.txt")); Assert.assertTrue(listener.changesDetected.contains("abcd.txt")); }
@Ignore @Test public void innersFirst() throws IOException { System.out.println("innersFirst"); TestFileChangeListener listener = new TestFileChangeListener(); File dir = getTempDir(); FileSystemWatcher watcher = new FileSystemWatcher(listener, -1, "test"); pause(1000); File f1 = create(dir, "Book$1.class"); watcher.register(f1); pause(1100); File f2 = create(dir, "Book.class"); watcher.register(f2); pause(1100); File f3 = create(dir, "Book$_2.class"); watcher.register(f3); pause(1100); watcher.setPaused(true); // Whilst paused, touch both files touch(f3); touch(f2); touch(f1); watcher.setPaused(false); pause(3000); System.out.println(listener.changesDetected); watcher.shutdown(); // Check that inners reported first assertEquals("Book$1.class", listener.changesDetected.get(0)); assertEquals("Book$_2.class", listener.changesDetected.get(1)); assertEquals("Book.class", listener.changesDetected.get(2)); }
@Test public void files() throws IOException { TestFileChangeListener listener = new TestFileChangeListener(); File dir = getTempDir(); FileSystemWatcher watcher = new FileSystemWatcher(listener, -1, "test"); pause(1000); File f1 = create(dir, "abc.txt"); watcher.register(f1); pause(1100); File f2 = create(dir, "abcd.txt"); watcher.register(f2); pause(1100); watcher.setPaused(true); // Whilst paused, touch both files touch(f2); touch(f1); watcher.setPaused(false); pause(3000); watcher.shutdown(); System.out.println(listener.changesDetected); assertEquals("abc.txt", listener.changesDetected.get(0)); assertEquals("abcd.txt", listener.changesDetected.get(1)); }