PermissionEntry implements Comparable<PermissionEntry>, PermissionConstants { boolean matches(@NotNull Tree tree, @Nullable PropertyState property) { return restriction == RestrictionPattern.EMPTY || restriction.matches(tree, property); } PermissionEntry(@NotNull String path, boolean isAllow, int index,
                    @NotNull PrivilegeBits privilegeBits,
                    @NotNull RestrictionPattern restriction); @Override int compareTo(@NotNull PermissionEntry pe); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testMatchesEmptyPattern() { assertTrue(entry.matches()); }
@Test public void testMatches() { when(pattern.matches()).thenReturn(true); assertTrue(entryWithNonEmptyPattern.matches()); when(pattern.matches()).thenReturn(false); assertFalse(entryWithNonEmptyPattern.matches()); }
@Test public void testMatchesTreeEmptyPattern() { assertTrue(entry.matches(mock(Tree.class), mock(PropertyState.class))); assertTrue(entry.matches(mock(Tree.class), null)); }
@Test public void testMatchesTree() { Tree t = mock(Tree.class); PropertyState ps = mock(PropertyState.class); when(pattern.matches(any(Tree.class), nullable(PropertyState.class))).thenReturn(true); assertTrue(entryWithNonEmptyPattern.matches(t, ps)); assertTrue(entryWithNonEmptyPattern.matches(t, null)); when(pattern.matches(any(Tree.class), nullable(PropertyState.class))).thenReturn(false); assertFalse(entryWithNonEmptyPattern.matches(t, ps)); assertFalse(entryWithNonEmptyPattern.matches(t, null)); verify(pattern, times(2)).matches(t, ps); verify(pattern, times(2)).matches(t, null); }
@Test public void testMatchesPathEmptyPattern() { assertTrue(entry.matches(path)); assertTrue(entry.matches(PathUtils.getParentPath(path))); assertTrue(entry.matches(PathUtils.concat(path, "some", "child"))); assertTrue(entry.matches("")); assertTrue(entry.matches("/some/other/path")); }
@Test public void testMatchesPath() { String[] paths = new String[] {path, PathUtils.getParentPath(path), PathUtils.concat(path, "some", "child"), "/some/other/path", ""}; when(pattern.matches(anyString())).thenReturn(true); for (String p : paths) { assertTrue(entryWithNonEmptyPattern.matches(p)); } when(pattern.matches(anyString())).thenReturn(false); for (String p : paths) { assertFalse(entryWithNonEmptyPattern.matches(p)); } for (String p : paths) { verify(pattern, times(2)).matches(p); } }