CompositeTreePermission implements TreePermission { @Override public boolean canRead() { if (canRead == null) { canRead = grantsRead(null); } return canRead; } private  CompositeTreePermission(@NotNull Tree tree, @NotNull TreeType type,
                                    @NotNull TreeProvider treeProvider,
                                    @NotNull TreeTypeProvider typeProvider,
                                    @NotNull AggregatedPermissionProvider[] providers,
                                    @NotNull TreePermission[] treePermissions, int cnt); @NotNull @Override TreePermission getChildPermission(@NotNull final String childName, @NotNull final NodeState childState); @Override boolean canRead(); @Override boolean canRead(@NotNull PropertyState property); @Override boolean canReadAll(); @Override boolean canReadProperties(); @Override boolean isGranted(long permissions); @Override boolean isGranted(long permissions, @NotNull PropertyState property);  }
@Test public void testEmpty() { TreePermission rootTp = createRootTreePermission(); assertSame(TreePermission.EMPTY, rootTp); assertFalse(rootTp.canRead()); }
@Test public void testCanRead() throws Exception { TreePermission rootTp = createRootTreePermission(fullScopeProvider, fullScopeProvider); Field f = CompositeTreePermission.class.getDeclaredField("canRead"); f.setAccessible(true); Object canRead = f.get(rootTp); assertNull(canRead); rootTp.canRead(); canRead = f.get(rootTp); assertNotNull(canRead); }
@Test public void testCanReadUnsupportedPermission() { TreePermission mockTp = when(mock(TreePermission.class).canRead()).thenReturn(true).getMock(); AggregatedPermissionProvider mockPP = mock(AggregatedPermissionProvider.class); when(mockPP.getTreePermission(any(Tree.class), any(TreeType.class), any(TreePermission.class))).thenReturn(mockTp); when(mockPP.supportedPermissions(mockTp, null, Permissions.READ_NODE)).thenReturn(Permissions.NO_PERMISSION); TreePermission rootTp = createRootTreePermission(mockPP, mockPP); assertFalse(rootTp.canRead()); verify(mockTp, never()).canRead(); verify(mockPP, times(2)).getTreePermission(any(Tree.class), any(TreeType.class), any(TreePermission.class)); verify(mockPP, times(2)).supportedPermissions(mockTp, null, Permissions.READ_NODE); }