Watcher { public void watch(Path path, final PathListener listener) throws IOException { FileAlterationObserver observer = observerFactory.create(path, listener); monitor.addObserver(observer); } @Inject  Watcher(ObserverFactory observerFactory, FileAlterationMonitor monitor); void watch(Path path, final PathListener listener);  }
@Test public void should_trigger_a_created_event_when_a_file_is_created() throws Exception { PathListenerStub listener = new PathListenerStub(); watcher.watch(folder.toPath(), listener); Path file = Files.createFile(subDirectory.resolve("file")); await().until(changedFilesContainsExactly(listener, file)); }
@Test public void should_trigger_a_modified_event_when_a_file_is_modified() throws Exception { Path existingFile = Files.createFile(subDirectory.resolve("file")); PathListenerStub listener = new PathListenerStub(); watcher.watch(folder.toPath(), listener); Files.write(existingFile, "hello".getBytes(), StandardOpenOption.APPEND); await().until(changedFilesContainsExactly(listener, existingFile)); }