PrivilegeUtil implements PrivilegeConstants { @NotNull public static PrivilegeDefinition readDefinition(@NotNull Tree definitionTree) { String name = definitionTree.getName(); boolean isAbstract = TreeUtil.getBoolean(definitionTree, REP_IS_ABSTRACT); Iterable<String> declAggrNames = null; PropertyState property = definitionTree.getProperty(REP_AGGREGATES); if (property != null) { declAggrNames = property.getValue(Type.NAMES); } return new ImmutablePrivilegeDefinition(name, isAbstract, declAggrNames); } private  PrivilegeUtil(); @NotNull static Tree getPrivilegesTree(Root root); @NotNull static PrivilegeDefinition readDefinition(@NotNull Tree definitionTree);  }
@Test public void testReadDefinitions() { Tree defTree = when(mock(Tree.class).getName()).thenReturn("name").getMock(); when(defTree.getProperty(PrivilegeConstants.REP_IS_ABSTRACT)).thenReturn(PropertyStates.createProperty(PrivilegeConstants.REP_IS_ABSTRACT, true)); PrivilegeDefinition def = PrivilegeUtil.readDefinition(defTree); assertEquals("name", def.getName()); assertTrue(def.isAbstract()); assertTrue(def.getDeclaredAggregateNames().isEmpty()); }
@Test public void testReadDefinitionsWithAggregates() { Iterable<String> aggregateNames = ImmutableSet.of(JCR_READ); Tree defTree = when(mock(Tree.class).getProperty(REP_AGGREGATES)).thenReturn(PropertyStates.createProperty(REP_AGGREGATES, aggregateNames, Type.NAMES)).getMock(); when(defTree.getName()).thenReturn("name"); PrivilegeDefinition def = PrivilegeUtil.readDefinition(defTree); assertEquals("name", def.getName()); assertTrue(Iterables.elementsEqual(aggregateNames, PrivilegeUtil.readDefinition(defTree).getDeclaredAggregateNames())); }