@Test
public void testRetrieveExistingFactsWithSearchResult() {

  UUID id = UUID.randomUUID();
  FactDocument document = new FactDocument().setId(id);
  FactEntity entity = new FactEntity().setId(id);
  FactRecord record = new FactRecord().setId(id);
  FactExistenceSearchCriteria criteria = createFactExistenceSearchCriteria();
  when(factRecordConverter.toCriteria(record)).thenReturn(criteria);
  when(factSearchManager.retrieveExistingFacts(criteria))
          .thenReturn(SearchResult.<FactDocument>builder().setCount(1).addValue(document).build());
  when(factManager.getFacts(anyList())).thenReturn(ListUtils.list(entity).iterator());
  when(factRecordConverter.fromEntity(entity)).thenReturn(record);
  ResultContainer<FactRecord> container = dao.retrieveExistingFacts(record);
  assertEquals(1, container.getCount());
  assertEquals(ListUtils.list(record), ListUtils.list(container));
  verify(factRecordConverter).toCriteria(record);
  verify(factSearchManager).retrieveExistingFacts(criteria);
  verify(factManager).getFacts(argThat(list -> list.contains(id)));
  verify(factRecordConverter).fromEntity(entity);
}