// Path: src/main/java/mirror/MirrorPaths.java
// public class MirrorPaths {
// 
//   public final Path root;
//   public final Path remoteRoot;
//   private final PathRules includes;
//   private final PathRules excludes;
//   private final boolean debugAll;
//   private final List<String> debugPrefixes;
// 
//   public static MirrorPaths forTesting(Path local) {
//     return new MirrorPaths(local, null, new PathRules(), new PathRules(), false, new ArrayList<>());
//   }
// 
//   public MirrorPaths(Path root, Path remoteRoot, PathRules includes, PathRules excludes, boolean debugAll, List<String> debugPrefixes) {
//     this.root = root;
//     this.remoteRoot = remoteRoot;
//     this.includes = includes;
//     this.excludes = excludes;
//     this.debugAll = debugAll;
//     this.debugPrefixes = debugPrefixes;
//   }
// 
//   public void addParameters(InitialSyncRequest.Builder req) {
//     req.addAllIncludes(includes.getLines());
//     req.addAllExcludes(excludes.getLines());
//     req.addAllDebugPrefixes(debugPrefixes);
//   }
// 
//   public boolean isIncluded(String path, boolean directory) {
//     return includes.matches(path, directory);
//   }
// 
//   public boolean isExcluded(String path, boolean directory) {
//     return excludes.matches(path, directory);
//   }
// 
//   public boolean shouldDebug(Node node) {
//     // avoid calcing the path if we have no prefixes anyway
//     if (debugAll) {
//       return true;
//     }
//     if (debugPrefixes.isEmpty()) {
//       return false;
//     }
//     return shouldDebug(node.getPath());
//   }
// 
//   public boolean shouldDebug(String path) {
//     if (debugAll) {
//       return true;
//     }
//     return debugPrefixes.stream().anyMatch(prefix -> path.startsWith(prefix));
//   }
// 
// }


import static com.google.common.collect.Lists.newArrayList;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import com.facebook.watchman.Callback;
import com.facebook.watchman.WatchmanClient.SubscriptionDescriptor;
import com.google.common.collect.ImmutableMap;
import mirror.MirrorPaths;
import mirror.Update;
package mirror.watchman;






/**
 * Tests {@link WatchmanFileWatcher}.
 */
public class WatchmanFileWatcherTest {

  private final class StubDescriptor extends SubscriptionDescriptor {
    @Override
    public String root() {
      return null;
    }

    @Override
    public String name() {
      return null;
    }
  }

  private static final String absRoot = "/foo/bar/zaz";
  private static final Path root = Paths.get(absRoot);
  private Watchman wm = null;
  private BlockingQueue<Update> queue = new ArrayBlockingQueue<Update>(100);
  private Map<String, Object> queryParams = new HashMap<>();

  @Test
  public void shouldHandleWatchProjectReturningAPrefix() throws Exception {
    // given we watch /foo/bar/zaz and /foo is already the watch root
    setupWatchman("/foo", Optional.of("bar/zaz"));
// Path: src/main/java/mirror/MirrorPaths.java
// public class MirrorPaths {
// 
//   public final Path root;
//   public final Path remoteRoot;
//   private final PathRules includes;
//   private final PathRules excludes;
//   private final boolean debugAll;
//   private final List<String> debugPrefixes;
// 
//   public static MirrorPaths forTesting(Path local) {
//     return new MirrorPaths(local, null, new PathRules(), new PathRules(), false, new ArrayList<>());
//   }
// 
//   public MirrorPaths(Path root, Path remoteRoot, PathRules includes, PathRules excludes, boolean debugAll, List<String> debugPrefixes) {
//     this.root = root;
//     this.remoteRoot = remoteRoot;
//     this.includes = includes;
//     this.excludes = excludes;
//     this.debugAll = debugAll;
//     this.debugPrefixes = debugPrefixes;
//   }
// 
//   public void addParameters(InitialSyncRequest.Builder req) {
//     req.addAllIncludes(includes.getLines());
//     req.addAllExcludes(excludes.getLines());
//     req.addAllDebugPrefixes(debugPrefixes);
//   }
// 
//   public boolean isIncluded(String path, boolean directory) {
//     return includes.matches(path, directory);
//   }
// 
//   public boolean isExcluded(String path, boolean directory) {
//     return excludes.matches(path, directory);
//   }
// 
//   public boolean shouldDebug(Node node) {
//     // avoid calcing the path if we have no prefixes anyway
//     if (debugAll) {
//       return true;
//     }
//     if (debugPrefixes.isEmpty()) {
//       return false;
//     }
//     return shouldDebug(node.getPath());
//   }
// 
//   public boolean shouldDebug(String path) {
//     if (debugAll) {
//       return true;
//     }
//     return debugPrefixes.stream().anyMatch(prefix -> path.startsWith(prefix));
//   }
// 
// }


// Path: src/test/java/mirror/watchman/WatchmanFileWatcherTest.java
import static com.google.common.collect.Lists.newArrayList;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import com.facebook.watchman.Callback;
import com.facebook.watchman.WatchmanClient.SubscriptionDescriptor;
import com.google.common.collect.ImmutableMap;
import mirror.MirrorPaths;
import mirror.Update;

package mirror.watchman;






/**
 * Tests {@link WatchmanFileWatcher}.
 */
public class WatchmanFileWatcherTest {

  private final class StubDescriptor extends SubscriptionDescriptor {
    @Override
    public String root() {
      return null;
    }

    @Override
    public String name() {
      return null;
    }
  }

  private static final String absRoot = "/foo/bar/zaz";
  private static final Path root = Paths.get(absRoot);
  private Watchman wm = null;
  private BlockingQueue<Update> queue = new ArrayBlockingQueue<Update>(100);
  private Map<String, Object> queryParams = new HashMap<>();

  @Test
  public void shouldHandleWatchProjectReturningAPrefix() throws Exception {
    // given we watch /foo/bar/zaz and /foo is already the watch root
    setupWatchman("/foo", Optional.of("bar/zaz"));
    WatchmanFileWatcher fw = new WatchmanFileWatcher(wm, MirrorPaths.forTesting(root), queue);