CugPolicyImpl implements CugPolicy { @Override public boolean removePrincipals(@NotNull Principal... principals) throws AccessControlException { checkIsMutable(); boolean modified = false; for (Principal principal : principals) { if (principal != null && this.principals.containsKey(principal.getName())) { this.principals.remove(principal.getName()); modified = true; } } return modified; } CugPolicyImpl(@NotNull String oakPath, @NotNull NamePathMapper namePathMapper,
                  @NotNull PrincipalManager principalManager, int importBehavior, @NotNull CugExclude cugExclude);   CugPolicyImpl(@NotNull String oakPath, @NotNull NamePathMapper namePathMapper,
                  @NotNull PrincipalManager principalManager, int importBehavior,
                  @NotNull CugExclude cugExclude, @NotNull Iterable<Principal> principals, boolean immutable); @NotNull @Override Set<Principal> getPrincipals(); @Override boolean addPrincipals(@NotNull Principal... principals); @Override boolean removePrincipals(@NotNull Principal... principals); @Override String getPath();  }
@Test public void testRemovePrincipals() throws Exception { CugPolicy cug = createCugPolicy(ImportBehavior.BESTEFFORT, ImmutableSet.of(testPrincipal, EveryonePrincipal.getInstance())); assertFalse(cug.removePrincipals(new PrincipalImpl("unknown"))); assertTrue(cug.removePrincipals(testPrincipal, EveryonePrincipal.getInstance(), new PrincipalImpl("unknown"))); assertTrue(cug.getPrincipals().isEmpty()); }
@Test public void removeExcludedPrincipal() throws Exception { Principal excluded = getExcludedPrincipal(); CugPolicyImpl cug = createCugPolicy(ImportBehavior.ABORT, Collections.singleton(excluded)); assertTrue(cug.removePrincipals(excluded)); }
@Test(expected = AccessControlException.class) public void testImmutableRemovePrincipals() throws Exception { CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.ABORT, exclude, principals, true); cug.removePrincipals(EveryonePrincipal.getInstance()); }