/*
 * Copyright 2017 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
package io.flutter.utils;

import com.google.common.collect.ImmutableSet;
import com.intellij.openapi.vfs.VirtualFile;
import io.flutter.testing.ProjectFixture;
import io.flutter.testing.TestDir;
import io.flutter.testing.Testing;
import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;

/**
 * Verifies that we can watch files and directories.
 */
public class FileWatchTest {
  @Rule
  public final ProjectFixture fixture = Testing.makeEmptyProject();

  @Rule
  public final TestDir tmp = new TestDir();

  @Test
  public void shouldFireEvents() throws Exception {
    final VirtualFile dir = tmp.ensureDir("abc");

    final AtomicInteger eventCount = new AtomicInteger();
    final FileWatch fileWatch = FileWatch.subscribe(dir, ImmutableSet.of("child"), eventCount::incrementAndGet);
    assertEquals(0, eventCount.get());

    // create
    tmp.writeFile("abc/child", "");
    assertEquals(1, eventCount.get());

    // modify
    tmp.writeFile("abc/child", "hello");
    assertEquals(2, eventCount.get());

    // delete
    tmp.deleteFile("abc/child");
    assertEquals(3, eventCount.get());
  }
}

@@ -538,16 +538,64 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNotEquals;
 %0A%0A/**%0A *
@@ -1176,24 +1176,140 @@
 hild%22, %22%22);%0A
+    int count;%0A    // The number of events fired is an implementation detail of the VFS. We just need at least one.%0A
     assertEq
@@ -1310,17 +1310,28 @@
 sert
+Not
 Equals(
-1,
+0, count =
  eve
@@ -1419,17 +1419,25 @@
 tEquals(
-2
+count + 1
 , eventC
@@ -1518,9 +1518,17 @@
 als(
-3
+count + 2
 , ev

Fix FileWatchTest (#3385)