@Override
  public void run() {
    log.info("Starting file watcher to watch for changes: " + file);
    try {
      while (!shutdown && key.isValid()) {
        try {
          handleNextWatchNotification();
        } catch (Exception e) {
          log.error("Watch service caught exception, will continue:" + e);
        }
      }
    } finally {
      log.info("Stopped watching for TLS cert changes");
      try {
        watchService.close();
      } catch (IOException e) {
        log.info("Error closing watch service", e);
      }
    }
  }
@Test
  public void shouldDetectFileUpdated() throws Exception {
    // Given:
    Files.write(filePath, someBytes, StandardOpenOption.CREATE_NEW);

    waitForLastModifiedTick();

    watcher = new FileWatcher(filePath, callback);
    watcher.start();

    // When:
    Files.write(filePath, someBytes);

    // Then:
    // verify that this happens at least once, there's a possibility that the callback
    // gets called multiple times for one underlying change
    verify(callback, timeout(TimeUnit.MINUTES.toMillis(1)).atLeastOnce()).run();
  }