PrivilegeBits implements PrivilegeConstants { public static PrivilegeBits getInstance() { return new PrivilegeBits(new ModifiableData()); } private  PrivilegeBits(Data d); static PrivilegeBits getInstance(); @NotNull static PrivilegeBits getInstance(@NotNull PrivilegeBits... base); @NotNull static PrivilegeBits getInstance(@Nullable PropertyState property); @NotNull static PrivilegeBits getInstance(@Nullable Tree tree); static long calculatePermissions(@NotNull PrivilegeBits bits,
                                            @NotNull PrivilegeBits parentBits,
                                            boolean isAllow); boolean isEmpty(); @NotNull PrivilegeBits unmodifiable(); @NotNull PrivilegeBits modifiable(); boolean includes(@NotNull PrivilegeBits otherBits); boolean isBuiltin(); @NotNull PrivilegeBits add(@NotNull PrivilegeBits other); @NotNull PrivilegeBits diff(@NotNull PrivilegeBits other); @NotNull PrivilegeBits addDifference(@NotNull PrivilegeBits a, @NotNull PrivilegeBits b); @NotNull PrivilegeBits retain(@NotNull PrivilegeBits other); @NotNull PropertyState asPropertyState(@NotNull String name); @NotNull PrivilegeBits nextBits(); void writeTo(@NotNull Tree tree); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static final PrivilegeBits EMPTY; static final Map<String, PrivilegeBits> BUILT_IN; static final PrivilegeBits NEXT_AFTER_BUILT_INS; }
@Test public void testGetInstance() { PrivilegeBits pb = PrivilegeBits.getInstance(); assertEquivalent(PrivilegeBits.EMPTY, pb); assertNotSame(PrivilegeBits.EMPTY, pb); assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); pb.diff(READ_NODES_PRIVILEGE_BITS); pb = PrivilegeBits.getInstance(PrivilegeBits.EMPTY); assertEquivalent(PrivilegeBits.EMPTY, pb); assertNotSame(PrivilegeBits.EMPTY, pb); assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); pb.diff(READ_NODES_PRIVILEGE_BITS); pb = PrivilegeBits.getInstance(READ_NODES_PRIVILEGE_BITS); assertEquivalent(READ_NODES_PRIVILEGE_BITS, pb); assertNotSame(READ_NODES_PRIVILEGE_BITS, pb); assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, PrivilegeBits.EMPTY); pb.diff(READ_NODES_PRIVILEGE_BITS); pb = PrivilegeBits.EMPTY; assertEquivalent(pb, PrivilegeBits.EMPTY); assertSame(PrivilegeBits.EMPTY, pb); assertSame(pb, pb.unmodifiable()); try { pb.add(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } try { pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } try { pb.diff(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } }
@Test public void testGetInstanceFromNullPropertyState() { assertSame(PrivilegeBits.EMPTY, PrivilegeBits.getInstance((PropertyState) null)); }
@Test(expected = IllegalArgumentException.class) public void testGetInstanceFromNegativeLong() { PrivilegeBits.getInstance(PropertyStates.createProperty("name", Collections.singleton(NO_PRIVILEGE-1), Type.LONGS)); }
@Test public void testGetInstanceFromTreeJcrRead() { Tree readPrivTree = mock(Tree.class); when(readPrivTree.getName()).thenReturn(JCR_READ); assertEquals(BUILT_IN.get(JCR_READ), PrivilegeBits.getInstance(readPrivTree)); }
@Test public void testGetInstanceFromNullTree() { assertSame(PrivilegeBits.EMPTY, PrivilegeBits.getInstance((Tree) null)); }
@Test public void testGetInstanceFromPrivilegesRootTree() { Tree tree = when(mock(Tree.class).getName()).thenReturn(REP_PRIVILEGES).getMock(); PrivilegeBits.getInstance(tree); Mockito.verify(tree, times(1)).getProperty(REP_NEXT); }