GetVisibleBranchDocIdsTask implements Callable<BitSet> { @Override public BitSet call() throws IOException { List<String> branches = Lists.newArrayList(permissionEvaluator.getBranchesForPermission(authentication, Permission.VIEW)); if (!branches.isEmpty()) { Collections.sort(branches); BooleanQuery allBranchesQuery = new BooleanQuery(); for (String projectAndBranch : branches) { String projectName = StringUtils.substringBefore(projectAndBranch, "/"); String branchName = StringUtils.substringAfter(projectAndBranch, "/"); TermQuery projectQuery = new TermQuery(new Term(PageIndex.PROJECT, projectName)); TermQuery branchQuery = new TermQuery(new Term(PageIndex.BRANCH, branchName)); BooleanQuery projectAndBranchQuery = new BooleanQuery(); projectAndBranchQuery.add(projectQuery, BooleanClause.Occur.MUST); projectAndBranchQuery.add(branchQuery, BooleanClause.Occur.MUST); allBranchesQuery.add(projectAndBranchQuery, BooleanClause.Occur.SHOULD); } AbstractDocIdsCollector collector = new AllDocIdsCollector(); searcher.search(allBranchesQuery, collector); return collector.getDocIds(); } else { return new BitSet(1); } } GetVisibleBranchDocIdsTask(IndexSearcher searcher, Authentication authentication,
			DocumentrPermissionEvaluator permissionEvaluator); @Override BitSet call();  }
@Test public void call() throws IOException { List<String> branches = Lists.newArrayList("project1/branch1", "project1/branch2", "project2/branch"); when(permissionEvaluator.getBranchesForPermission(authentication, Permission.VIEW)) .thenReturn(Sets.newHashSet(branches)); BooleanQuery query = new BooleanQuery(); for (String projectAndBranch : branches) { BooleanQuery q = new BooleanQuery(); String projectName = StringUtils.substringBefore(projectAndBranch, "/"); String branchName = StringUtils.substringAfter(projectAndBranch, "/"); q.add(new TermQuery(new Term(PageIndex.PROJECT, projectName)), BooleanClause.Occur.MUST); q.add(new TermQuery(new Term(PageIndex.BRANCH, branchName)), BooleanClause.Occur.MUST); query.add(q, BooleanClause.Occur.SHOULD); } task.call(); verify(searcher).search(eq(query), Matchers.any(AllDocIdsCollector.class)); }