ItemNamePattern implements RestrictionPattern { @Override public boolean matches(@NotNull Tree tree, @Nullable PropertyState property) { if (property != null) { return names.contains(property.getName()); } else { return names.contains(tree.getName()); } } ItemNamePattern(Iterable<String> names); @Override boolean matches(@NotNull Tree tree, @Nullable PropertyState property); @Override boolean matches(@NotNull String path); @Override boolean matches(); @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test public void testMatchesItem() throws Exception { Tree rootTree = root.getTree("/"); List<String> matching = ImmutableList.of("a", "b", "c", "d/e/a", "a/b/c/d/b", "test/c"); for (String relPath : matching) { Tree testTree = addTree(rootTree, relPath); assertTrue(pattern.matches(testTree, null)); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } List<String> notMatching = ImmutableList.of("d", "b/d", "d/e/f", "c/b/abc"); for (String relPath : notMatching) { Tree testTree = addTree(rootTree, relPath); assertFalse(pattern.matches(testTree, null)); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } }
@Test public void testMatchesPath() { List<String> matching = ImmutableList.of("/a", "/b", "/c", "/d/e/a", "/a/b/c/d/b", "/test/c"); for (String p : matching) { assertTrue(pattern.matches(p)); } List<String> notMatching = ImmutableList.of("/", "/d", "/b/d", "/d/e/f", "/c/b/abc"); for (String p : notMatching) { assertFalse(pattern.matches(p)); } }
@Test public void testMatchesNull() { assertFalse(pattern.matches()); }