CompositePrincipalProvider implements PrincipalProvider { @Nullable @Override public ItemBasedPrincipal getItemBasedPrincipal(@NotNull String principalOakPath) { for (PrincipalProvider provider : providers) { ItemBasedPrincipal principal = provider.getItemBasedPrincipal(principalOakPath); if (principal != null) { return principal; } } return null; } 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 testGetItemBasedPrincipalDefault() throws Exception { for (Principal p : testPrincipals()) { if (p instanceof ItemBasedPrincipal) { assertNull(cpp.getItemBasedPrincipal(((ItemBasedPrincipal) p).getPath())); } } }
@Test public void testGetItemBasedPrincipal() throws Exception { ItemBasedPrincipal p = mock(ItemBasedPrincipal.class); PrincipalProvider pp = when(mock(PrincipalProvider.class).getItemBasedPrincipal(anyString())).thenReturn(p).getMock(); assertEquals(p, CompositePrincipalProvider.of(ImmutableList.of(pp, pp2)).getItemBasedPrincipal("/any/path")); }