CugPolicyImpl implements CugPolicy { @Override public boolean addPrincipals(@NotNull Principal... principals) throws AccessControlException { checkIsMutable(); boolean modified = false; for (Principal principal : principals) { if (isValidPrincipal(principal) && !this.principals.containsKey(principal.getName())) { this.principals.put(principal.getName(), principal); 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 testAddPrincipals() throws Exception { CugPolicy empty = createEmptyCugPolicy(); assertTrue(empty.addPrincipals(EveryonePrincipal.getInstance())); assertFalse(empty.addPrincipals(EveryonePrincipal.getInstance())); CugPolicy cug = createCugPolicy(principals); assertTrue(cug.addPrincipals(EveryonePrincipal.getInstance())); assertFalse(cug.addPrincipals(EveryonePrincipal.getInstance())); }
@Test(expected = AccessControlException.class) public void testAddInvalidPrincipalsAbort() throws Exception { CugPolicy cug = createEmptyCugPolicy(ImportBehavior.ABORT); cug.addPrincipals( EveryonePrincipal.getInstance(), new PrincipalImpl("unknown")); }
@Test(expected = AccessControlException.class) public void testAddEmptyPrincipalName() throws Exception { CugPolicy cug = createEmptyCugPolicy(ImportBehavior.BESTEFFORT); cug.addPrincipals(new PrincipalImpl("")); }
@Test(expected = AccessControlException.class) public void testAddNullPrincipalName() throws Exception { CugPolicy cug = createEmptyCugPolicy(ImportBehavior.BESTEFFORT); cug.addPrincipals((Principal) () -> null); }
@Test public void testAddSingleExcludedPrincipal() throws Exception { CugPolicy cug = createEmptyCugPolicy(ImportBehavior.ABORT); assertFalse(cug.addPrincipals(getExcludedPrincipal())); }
@Test(expected = AccessControlException.class) public void testImmutableAddPrincipals() throws Exception { CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.ABORT, exclude, principals, true); cug.addPrincipals(EveryonePrincipal.getInstance()); }