@Test(timeout = 2000)
  public void testWatchForMultipleEventTypes() throws IOException, InterruptedException {
    JimfsPath path = createDirectory();
    watcher.register(path, ImmutableList.of(ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY));

    Files.createDirectory(path.resolve("foo"));
    Files.createFile(path.resolve("bar"));

    assertWatcherHasEvents(
        new Event<>(ENTRY_CREATE, 1, fs.getPath("bar")),
        new Event<>(ENTRY_CREATE, 1, fs.getPath("foo")));

    Files.createFile(path.resolve("baz"));
    Files.delete(path.resolve("bar"));
    Files.createFile(path.resolve("foo/bar"));

    assertWatcherHasEvents(
        new Event<>(ENTRY_CREATE, 1, fs.getPath("baz")),
        new Event<>(ENTRY_DELETE, 1, fs.getPath("bar")),
        new Event<>(ENTRY_MODIFY, 1, fs.getPath("foo")));

    Files.delete(path.resolve("foo/bar"));
    ensureTimeToPoll(); // watcher polls, seeing modification, then polls again, seeing delete
    Files.delete(path.resolve("foo"));

    assertWatcherHasEvents(
        new Event<>(ENTRY_MODIFY, 1, fs.getPath("foo")),
        new Event<>(ENTRY_DELETE, 1, fs.getPath("foo")));

    Files.createDirectories(path.resolve("foo/bar"));

    // polling here may either see just the creation of foo, or may first see the creation of foo
    // and then the creation of foo/bar (modification of foo) since those don't happen atomically
    assertWatcherHasEvents(
        ImmutableList.<WatchEvent<?>>of(new Event<>(ENTRY_CREATE, 1, fs.getPath("foo"))),
        // or
        ImmutableList.<WatchEvent<?>>of(
            new Event<>(ENTRY_CREATE, 1, fs.getPath("foo")),
            new Event<>(ENTRY_MODIFY, 1, fs.getPath("foo"))));

    Files.delete(path.resolve("foo/bar"));
    Files.delete(path.resolve("foo"));

    // polling here may either just see the deletion of foo, or may first see the deletion of bar
    // (modification of foo) and then the deletion of foo
    assertWatcherHasEvents(
        ImmutableList.<WatchEvent<?>>of(new Event<>(ENTRY_DELETE, 1, fs.getPath("foo"))),
        // or
        ImmutableList.<WatchEvent<?>>of(
            new Event<>(ENTRY_MODIFY, 1, fs.getPath("foo")),
            new Event<>(ENTRY_DELETE, 1, fs.getPath("foo"))));
  }
Tests for {@link PollingWatchService}.

@author Colin Decker
jimfs/src/test/java/com/google/common/jimfs/PollingWatchServiceTest.java