### Question:
ObjectFactDaoFacade implements ObjectFactDao { @Override public ResultContainer<FactRecord> retrieveExistingFacts(FactRecord record) { SearchResult<FactDocument> searchResult = factSearchManager.retrieveExistingFacts(factRecordConverter.toCriteria(record)); if (searchResult.getCount() <= 0) { return ResultContainer.<FactRecord>builder().build(); } return createResultContainer(searchResult.getValues().iterator(), searchResult.getCount()); } @Inject  ObjectFactDaoFacade(ObjectManager objectManager,
                             FactManager factManager,
                             FactSearchManager factSearchManager,
                             ObjectRecordConverter objectRecordConverter,
                             FactRecordConverter factRecordConverter,
                             FactAclEntryRecordConverter factAclEntryRecordConverter,
                             FactCommentRecordConverter factCommentRecordConverter,
                             Consumer<FactRecord> dcReplicationConsumer); @Override ObjectRecord getObject(UUID id); @Override ObjectRecord getObject(String type, String value); @Override ObjectRecord storeObject(ObjectRecord record); @Override ObjectStatisticsContainer calculateObjectStatistics(ObjectStatisticsCriteria criteria); @Override ResultContainer<ObjectRecord> searchObjects(FactSearchCriteria criteria); @Override FactRecord getFact(UUID id); @Override FactRecord storeFact(FactRecord record); @Override FactRecord refreshFact(FactRecord record); @Override FactRecord retractFact(FactRecord record); @Override ResultContainer<FactRecord> retrieveExistingFacts(FactRecord record); @Override ResultContainer<FactRecord> searchFacts(FactSearchCriteria criteria); @Override FactAclEntryRecord storeFactAclEntry(FactRecord fact, FactAclEntryRecord aclEntry); @Override FactCommentRecord storeFactComment(FactRecord fact, FactCommentRecord comment);  }### Answer:
@Test public void testRetrieveExistingFactsWithoutSearchResult() { FactRecord record = new FactRecord(); FactExistenceSearchCriteria criteria = createFactExistenceSearchCriteria(); when(factRecordConverter.toCriteria(record)).thenReturn(criteria); when(factSearchManager.retrieveExistingFacts(criteria)).thenReturn(SearchResult.<FactDocument>builder().build()); ResultContainer<FactRecord> container = dao.retrieveExistingFacts(record); assertEquals(0, container.getCount()); assertFalse(container.hasNext()); verify(factRecordConverter).toCriteria(record); verify(factSearchManager).retrieveExistingFacts(criteria); verifyNoInteractions(factManager); }
@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); }