@Test public void search_JudgmentsFound() { Judgment ccJudgment = TestInMemoryObjectFactory.createCcJudgment(); Whitebox.setInternalState(ccJudgment, "id", 19l); Judgment nacJudgment = TestInMemoryObjectFactory.createNacJudgment(); Whitebox.setInternalState(nacJudgment, "id", 29l); List<Judgment> judgments = Lists.newArrayList(ccJudgment, nacJudgment); searchResult = new SearchResult<Judgment>(judgments, 2l, 0, 10); Mockito.<SearchResult<Judgment>>when(databaseSearchService.search(searchFilter)).thenReturn(searchResult); EnrichmentTag enrichmentTag = createEnrichmentTag(ccJudgment.getId(), EnrichmentTagTypes.REFERENCED_COURT_CASES, "{'xxx':'yyy'}"); List<EnrichmentTag> enrichmentTags = Lists.newArrayList(enrichmentTag); List<Long> judgmentIds = Lists.newArrayList(ccJudgment.getId(), nacJudgment.getId()); when(enrichmentTagRepository.findAllByJudgmentIds(judgmentIds)).thenReturn(enrichmentTags); judgmentEnrichmentDbSearchService.search(searchFilter); verify(databaseSearchService).search(searchFilter); verify(enrichmentTagRepository).findAllByJudgmentIds(judgmentIds); verify(judgmentEnrichmentService).enrich(ccJudgment, enrichmentTags); verify(judgmentEnrichmentService).enrich(nacJudgment, Lists.newArrayList()); verifyNoMoreInteractions(databaseSearchService, enrichmentTagRepository, judgmentEnrichmentService); }
public SearchResult<Judgment> search(JudgmentSearchFilter searchFilter) { Preconditions.checkNotNull(searchFilter); SearchResult<Judgment> searchResult = databaseSearchService.search(searchFilter); if (searchFilter.isWithGenerated() != null && !searchFilter.isWithGenerated()) { return searchResult; } if (CollectionUtils.isEmpty(searchResult.getResultRecords())) { return searchResult; } List<Judgment> judgments = searchResult.getResultRecords(); List<EnrichmentTag> enrichmentTags = enrichmentTagRepository.findAllByJudgmentIds(extractJudgmentIds(judgments)); for (Judgment judgment : judgments) { List<EnrichmentTag> judgmentEnrichmentTags = extractEnrichmentTags(enrichmentTags, judgment); judgmentEnrichmentService.enrich(judgment, judgmentEnrichmentTags); } return searchResult; }
JudgmentEnrichmentDbSearchService { public SearchResult<Judgment> search(JudgmentSearchFilter searchFilter) { Preconditions.checkNotNull(searchFilter); SearchResult<Judgment> searchResult = databaseSearchService.search(searchFilter); if (searchFilter.isWithGenerated() != null && !searchFilter.isWithGenerated()) { return searchResult; } if (CollectionUtils.isEmpty(searchResult.getResultRecords())) { return searchResult; } List<Judgment> judgments = searchResult.getResultRecords(); List<EnrichmentTag> enrichmentTags = enrichmentTagRepository.findAllByJudgmentIds(extractJudgmentIds(judgments)); for (Judgment judgment : judgments) { List<EnrichmentTag> judgmentEnrichmentTags = extractEnrichmentTags(enrichmentTags, judgment); judgmentEnrichmentService.enrich(judgment, judgmentEnrichmentTags); } return searchResult; } }
JudgmentEnrichmentDbSearchService { public SearchResult<Judgment> search(JudgmentSearchFilter searchFilter) { Preconditions.checkNotNull(searchFilter); SearchResult<Judgment> searchResult = databaseSearchService.search(searchFilter); if (searchFilter.isWithGenerated() != null && !searchFilter.isWithGenerated()) { return searchResult; } if (CollectionUtils.isEmpty(searchResult.getResultRecords())) { return searchResult; } List<Judgment> judgments = searchResult.getResultRecords(); List<EnrichmentTag> enrichmentTags = enrichmentTagRepository.findAllByJudgmentIds(extractJudgmentIds(judgments)); for (Judgment judgment : judgments) { List<EnrichmentTag> judgmentEnrichmentTags = extractEnrichmentTags(enrichmentTags, judgment); judgmentEnrichmentService.enrich(judgment, judgmentEnrichmentTags); } return searchResult; }  }
JudgmentEnrichmentDbSearchService { public SearchResult<Judgment> search(JudgmentSearchFilter searchFilter) { Preconditions.checkNotNull(searchFilter); SearchResult<Judgment> searchResult = databaseSearchService.search(searchFilter); if (searchFilter.isWithGenerated() != null && !searchFilter.isWithGenerated()) { return searchResult; } if (CollectionUtils.isEmpty(searchResult.getResultRecords())) { return searchResult; } List<Judgment> judgments = searchResult.getResultRecords(); List<EnrichmentTag> enrichmentTags = enrichmentTagRepository.findAllByJudgmentIds(extractJudgmentIds(judgments)); for (Judgment judgment : judgments) { List<EnrichmentTag> judgmentEnrichmentTags = extractEnrichmentTags(enrichmentTags, judgment); judgmentEnrichmentService.enrich(judgment, judgmentEnrichmentTags); } return searchResult; }  SearchResult<Judgment> search(JudgmentSearchFilter searchFilter); @Autowired void setDatabaseSearchService(DatabaseSearchService databaseSearchService); @Autowired void setEnrichmentTagRepository(EnrichmentTagRepository enrichmentTagRepository); @Autowired void setJudgmentEnrichmentService(JudgmentEnrichmentService judgmentEnrichmentService); }
JudgmentEnrichmentDbSearchService { public SearchResult<Judgment> search(JudgmentSearchFilter searchFilter) { Preconditions.checkNotNull(searchFilter); SearchResult<Judgment> searchResult = databaseSearchService.search(searchFilter); if (searchFilter.isWithGenerated() != null && !searchFilter.isWithGenerated()) { return searchResult; } if (CollectionUtils.isEmpty(searchResult.getResultRecords())) { return searchResult; } List<Judgment> judgments = searchResult.getResultRecords(); List<EnrichmentTag> enrichmentTags = enrichmentTagRepository.findAllByJudgmentIds(extractJudgmentIds(judgments)); for (Judgment judgment : judgments) { List<EnrichmentTag> judgmentEnrichmentTags = extractEnrichmentTags(enrichmentTags, judgment); judgmentEnrichmentService.enrich(judgment, judgmentEnrichmentTags); } return searchResult; }  SearchResult<Judgment> search(JudgmentSearchFilter searchFilter); @Autowired void setDatabaseSearchService(DatabaseSearchService databaseSearchService); @Autowired void setEnrichmentTagRepository(EnrichmentTagRepository enrichmentTagRepository); @Autowired void setJudgmentEnrichmentService(JudgmentEnrichmentService judgmentEnrichmentService);  }