DeclaredMembershipPredicate implements Predicate<Authorizable> { @Override public boolean apply(@Nullable Authorizable authorizable) { String id = saveGetContentId(authorizable); if (id != null) { if (declaredMemberContentIds.contains(id)) { return true; } else { while (contentIdIterator.hasNext()) { String memberContentId = contentIdIterator.next(); declaredMemberContentIds.add(memberContentId); if (memberContentId.equals(id)) { return true; } } } } return false; } DeclaredMembershipPredicate(UserManagerImpl userManager, String groupId); @Override boolean apply(@Nullable Authorizable authorizable);  }
@Test public void testUnknownGroupId() throws Exception { String id = "unknownGroupId"; assertNull(userManager.getAuthorizable(id)); Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(id); assertFalse(predicate.apply(testUser)); assertFalse(predicate.apply(testGroup)); assertFalse(predicate.apply(inheritedMember)); assertFalse(predicate.apply(null)); }
@Test public void testUserId() throws Exception { Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(testUser.getID()); assertFalse(predicate.apply(testUser)); assertFalse(predicate.apply(testGroup)); assertFalse(predicate.apply(inheritedMember)); assertFalse(predicate.apply(null)); }
@Test public void testMembers() throws Exception { Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(testGroup.getID()); assertTrue(predicate.apply(testMember)); assertTrue(predicate.apply(testUser)); assertFalse(predicate.apply(testGroup)); assertFalse(predicate.apply(inheritedMember)); assertFalse(predicate.apply(null)); }
@Test public void testApplyTwice() throws Exception { Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(testGroup.getID()); predicate.apply(testMember); assertTrue(predicate.apply(testMember)); }
@Test public void testApplyTwiceNotMember() throws Exception { Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(testGroup.getID()); predicate.apply(inheritedMember); assertFalse(predicate.apply(inheritedMember)); }
@Test public void testGetIdFails() throws Exception { Predicate<Authorizable> predicate = getDeclaredMembershipPredicate(testGroup.getID()); Authorizable a = Mockito.mock(Authorizable.class); when(a.getID()).thenThrow(new RepositoryException()); assertFalse(predicate.apply(a)); }