CompositePrincipalProvider implements PrincipalProvider { @NotNull @Override public Iterator<Principal> findPrincipals(@Nullable String nameHint, int searchType) { Iterator<? extends Principal>[] iterators = new Iterator[providers.size()]; int i = 0; for (PrincipalProvider provider : providers) { if (nameHint == null) { iterators[i++] = provider.findPrincipals(searchType); } else { iterators[i++] = provider.findPrincipals(nameHint, searchType); } } return Iterators.concat(iterators); } CompositePrincipalProvider(List<PrincipalProvider> providers); static PrincipalProvider of(@NotNull List<PrincipalProvider> providers); @Nullable @Override Principal getPrincipal(@NotNull String principalName); @Nullable @Override ItemBasedPrincipal getItemBasedPrincipal(@NotNull String principalOakPath); @NotNull @Override Set<Principal> getMembershipPrincipals(@NotNull Principal principal); @NotNull @Override Set<Principal> getPrincipals(@NotNull String userID); @NotNull @Override Iterator<Principal> findPrincipals(@Nullable String nameHint, int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, boolean fullText, int searchType,
            long offset, long limit);  }
@Test public void findPrincipalsUnknown() { assertFalse(cpp.findPrincipals(TestPrincipalProvider.UNKNOWN.getName(), PrincipalManager.SEARCH_TYPE_ALL).hasNext()); assertFalse(cpp.findPrincipals(TestPrincipalProvider.UNKNOWN.getName(), PrincipalManager.SEARCH_TYPE_NOT_GROUP).hasNext()); assertFalse(cpp.findPrincipals(TestPrincipalProvider.UNKNOWN.getName(), PrincipalManager.SEARCH_TYPE_GROUP).hasNext()); }
@Test public void findPrincipalsByTypeNotGroup() { Iterable<? extends Principal> expected = Iterables.filter(testPrincipals(), input -> !(input instanceof GroupPrincipal)); Iterator<? extends Principal> result = cpp.findPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP); assertIterator(expected, result); }