IdeaService { public Page<IdeaOut> fetchIdeasByRequestorHasVoted(String campaignId, boolean hasVoted, Integer page, Integer pageSize, UserEntity requestor) { Assert.notNull(campaignId, "campaignId must not be null"); final Set<String> ideaIds = voteRepository.findIdsByVoterId(requestor.getId()).stream().map(el -> el.getId().getIdeaId()).collect(Collectors.toSet()); final Page<IdeaEntity> dbRes; if (hasVoted) { dbRes = ideaRepository.findByCampaignIdAndStatusAndIdIn( campaignId, IdeaStatus.PUBLISHED, ideaIds, calcPageRequest(page, pageSize) ); } else { dbRes = ideaRepository.findByCampaignIdAndStatusAndIdNotIn( campaignId, IdeaStatus.PUBLISHED, ideaIds, calcPageRequest(page, pageSize) ); } return new PageImpl<>(toIdeas(dbRes.getContent(), requestor), calcPageRequest(page, pageSize), dbRes.getTotalElements()); }  IdeaOut fetchIdea(String ideaId, UserEntity requestor); Page<IdeaOut> fetchIdeasByStatus(String campaignId, Set<IdeaStatus> statusSet, Integer page, Integer pageSize, UserEntity requestor); Page<IdeaOut> fetchIdeasByRequestorHasVoted(String campaignId, boolean hasVoted, Integer page, Integer pageSize, UserEntity requestor); List<IdeaOut> fetchIdeasByCampaignAndCreator(String campaignId, UserEntity creator, UserEntity requestor); IdeaOut createNewIdea(String campaignId, IdeaIn cmd, UserEntity creator); IdeaOut modifyIdea(String ideaId, IdeaIn cmd, UserEntity requestingUser); void approveIdea(String campaignId, String ideaId, UserEntity approvingAdmin); void rejectIdea(String campaignId, String ideaId, String rejectionComment, UserEntity approvingAdmin); void voteForIdea(VoteCmd voteCmd, UserEntity voter);  }
@Test public void fetchIdeasByRequestorHasVoted_ShouldEnrichIdeas_ByRating() { final String campaignId = "test_campId"; final ArgumentCaptor<PageRequest> pReqCap = ArgumentCaptor.forClass(PageRequest.class); final IdeaEntity expIdea = Fixtures.givenIdeaEntity("ideaId"); final Set<String> ideasIds = Collections.singleton(expIdea.getId()); doReturn(Collections.singleton(new VoteEntity(new VoteId("votertestid", expIdea.getId()), 1))) .when(voteRepository).findIdsByVoterId(anyString()); doReturn(new PageImpl<>(singletonList(expIdea))).when(ideaRepository) .findByCampaignIdAndStatusAndIdIn(eq(campaignId), eq(IdeaStatus.PUBLISHED), eq(ideasIds), pReqCap.capture()); final Rating expRating = givenVoteRepositoryReturnsVotes(expIdea.getId()); final Page<IdeaOut> res = ideaService.fetchIdeasByRequestorHasVoted(campaignId, true, 0, 10, givenUserEntity("requestorId")); assertThat(res.getContent().get(0).getRating(), equalTo(expRating)); }