FileOps { public static void awaitChange(String file) { try { awaitChangeInterruptibly(file); } catch (InterruptedException e) { throw CheckedExceptions.throwAsRuntimeException(e); } } protected  FileOps(); static void append(String content, String file); static void awaitChange(String file); static void awaitChangeInterruptibly(String file); static String expandPath(String path); static String expandPath(String path, String cwd); static String getUserHome(); static String getWorkingDirectory(); static boolean isDirectory(String path); static void mkdirs(String path); static void mkdirs(Path path); static DirectoryStream<Path> newDirectoryStream(Path dir); static String read(String file); static List<String> readLines(final String file); static List<String> readLines(final String file, String cwd); static String tempDir(String prefix); static String tempFile(); static String tempFile(String prefix); static String tempFile(String prefix, String suffix); static String tempFile(String dir, String prefix, String suffix); static String touch(String file); static URL toURL(String path); static void write(String content, String file);  }
@Test(timeout = 10000) public void testAwaitChange() throws InterruptedException { String file = FileOps.tempFile(FileOps.tempDir("con"), "foo", ".test"); CountDownLatch latch = new CountDownLatch(1); Thread t = new Thread(() -> { FileOps.awaitChange(file); latch.countDown(); }); t.start(); AtomicBoolean done = new AtomicBoolean(false); Thread t2 = new Thread(() -> { while (!done.get()) { FileOps.write(Random.getSimpleString(), file); } }); t2.start(); latch.await(); Assert.assertTrue(true); done.set(true); }