CompiledPermissionImpl implements CompiledPermissions, PermissionConstants { @NotNull static CompiledPermissions create(@NotNull Root root, @NotNull String workspaceName, @NotNull PermissionStore store, @NotNull Set<Principal> principals, @NotNull ConfigurationParameters options, @NotNull Context ctx, @NotNull ProviderCtx providerCtx) { Tree permissionsTree = PermissionUtil.getPermissionsRoot(root, workspaceName); if (!permissionsTree.exists() || principals.isEmpty()) { return NoPermissions.getInstance(); } else { return new CompiledPermissionImpl(principals, root, workspaceName, store, options, ctx, providerCtx); } } private  CompiledPermissionImpl(@NotNull Set<Principal> principals,
                                   @NotNull Root root,
                                   @NotNull String workspaceName,
                                   @NotNull PermissionStore store,
                                   @NotNull ConfigurationParameters options,
                                   @NotNull Context ctx,
                                   @NotNull ProviderCtx providerCtx); @Override void refresh(@NotNull Root root, @NotNull String workspaceName); @NotNull @Override RepositoryPermission getRepositoryPermission(); @NotNull @Override TreePermission getTreePermission(@NotNull Tree tree, @NotNull TreePermission parentPermission); @NotNull @Override TreePermission getTreePermission(@NotNull Tree tree, @NotNull TreeType type, @NotNull TreePermission parentPermission); @Override boolean isGranted(@NotNull Tree tree, @Nullable PropertyState property, long permissions); @Override boolean isGranted(@NotNull String path, long permissions); @NotNull @Override Set<String> getPrivileges(@Nullable Tree tree); @Override boolean hasPrivileges(@Nullable Tree tree, @NotNull String... privilegeNames);  }
@Test public void testCreateFromEmptyPrincipals() { Set<Principal> principals = ImmutableSet.of(); assertSame(NoPermissions.getInstance(), CompiledPermissionImpl.create(root, "wspName", mock(PermissionStore.class), principals, ConfigurationParameters.EMPTY, mock(Context.class), mock(ProviderCtx.class))); }
@Test public void testCreateNonExistingPermissionStore() { Tree t = when(mock(Tree.class).exists()).thenReturn(false).getMock(); Root r = when(mock(Root.class).getTree(anyString())).thenReturn(t).getMock(); Set<Principal> principals = ImmutableSet.of(new PrincipalImpl("principalName")); assertSame(NoPermissions.getInstance(), CompiledPermissionImpl.create(r, "wspName", mock(PermissionStore.class), principals, ConfigurationParameters.EMPTY, mock(Context.class), mock(ProviderCtx.class))); }