FsHandle implements Closeable { public void addUpdateCallback(Consumer<EV_FileListing> callback) { if (callback == null) throw new IllegalArgumentException(); callbacks.add(callback); } FsHandle();  FsHandle(String start);  FsHandle(String start, FsHandleOptions options);  FsHandle(FileSystem fs, String start, FsHandleOptions options); int getId(); String pwd(); void addUpdateCallback(Consumer<EV_FileListing> callback); boolean up(); boolean down(String directory); boolean setPath(String path); List<FileListlet> list(); @Override void close();  }
@Test @DisplayName("Check that the add event listener is notified") void add_callback_1(@TempDir Path temp) throws IOException, InterruptedException { assumeFalse(SystemUtil.OS_TYPE == OsType.MACOS); BlockingQueue<FileListlet> eventQueue = new ArrayBlockingQueue<>(5); Files.createFile(temp.resolve("test.txt")); try (FsHandle fs = new FsHandle(temp.toString())) { fs.addUpdateCallback(ev -> { ev.getListingList().stream().forEachOrdered(eventQueue::add); }); Files.createFile(temp.resolve("added.txt")); FileListlet fileCreated = eventQueue.poll(5000, TimeUnit.MILLISECONDS); assertNotNull(fileCreated); assertEquals("added.txt", fileCreated.getName()); assertEquals(UpdateType.ENTRY_CREATE, fileCreated.getUpdateType()); assertEquals(0, eventQueue.size(), "Unexpected events: " + Arrays.toString(eventQueue.toArray())); } }
@Test @DisplayName("Check that the delete event listener is notified") void delete_callback_1(@TempDir Path temp) throws IOException, InterruptedException { assumeFalse(SystemUtil.OS_TYPE == OsType.MACOS); BlockingQueue<FileListlet> eventQueue = new ArrayBlockingQueue<>(5); Files.createFile(temp.resolve("test.txt")); try (FsHandle fs = new FsHandle(temp.toString())) { fs.addUpdateCallback(ev -> { ev.getListingList().stream().forEachOrdered(eventQueue::add); }); Files.delete(temp.resolve("test.txt")); FileListlet fileDeleted = eventQueue.poll(5000, TimeUnit.MILLISECONDS); assertNotNull(fileDeleted); assertEquals("test.txt", fileDeleted.getName()); assertEquals(UpdateType.ENTRY_DELETE, fileDeleted.getUpdateType()); assertEquals(0, eventQueue.size(), "Unexpected events: " + Arrays.toString(eventQueue.toArray())); } }
@Test @DisplayName("Check that the modify event listener is notified") void modify_callback_1(@TempDir Path temp) throws IOException, InterruptedException { assumeFalse(SystemUtil.OS_TYPE == OsType.MACOS); BlockingQueue<FileListlet> eventQueue = new ArrayBlockingQueue<>(5); Files.write(temp.resolve("test.txt"), "1234".getBytes()); try (FsHandle fs = new FsHandle(temp.toString())) { fs.addUpdateCallback(ev -> { ev.getListingList().stream().forEachOrdered(eventQueue::add); }); Files.write(temp.resolve("test.txt"), "5678".getBytes(), APPEND); FileListlet fileModified = eventQueue.poll(5000, TimeUnit.MILLISECONDS); assertNotNull(fileModified); assertEquals("test.txt", fileModified.getName()); assertEquals(UpdateType.ENTRY_MODIFY, fileModified.getUpdateType()); assertEquals(0, eventQueue.size(), "Unexpected events: " + Arrays.toString(eventQueue.toArray())); } }