ResourcesWatcher implements Closeable { public void await(Path resource) throws InterruptedException { if (!isStarted) { start(); } final CountDownLatch countDownLatch = new CountDownLatch(1); addChangedHandler(r -> { if (resource == null || r.equals(resource)) { countDownLatch.countDown(); } }); countDownLatch.await(); stop(); } ResourcesWatcher(List<Path> resources); void addChangedHandler(ResourceChangedHandler handler); void start(); void stop(); void await(Path resource); void await(); @Override void close();  }
@Test(timeout = 10000) public void testAwaitConcreteChange() throws Exception { scheduleFileChange(); resourcesWatcher.await(temporaryFile); assertThat(testHandler.getChangesCount(), equalTo(1)); Thread.sleep(1500); assertThat(testHandler.getChangesCount(), equalTo(1)); }
@Test(timeout = 10000) public void testAwaitAnyChange() throws Exception { scheduleFileChange(); resourcesWatcher.await(); assertThat(testHandler.getChangesCount(), equalTo(1)); }