### Question:
ObjectFactDaoFacade implements ObjectFactDao { @Override public ResultContainer<ObjectRecord> searchObjects(FactSearchCriteria criteria) { SearchResult<ObjectDocument> searchResult = factSearchManager.searchObjects(criteria); if (searchResult.getCount() <= 0) { return ResultContainer.<ObjectRecord>builder().build(); } Iterator<UUID> idIterator = new MappingIterator<>(searchResult.getValues().iterator(), ObjectDocument::getId); Iterator<ObjectEntity> batchingIterator = new BatchingIterator<>(idIterator, objectManager::getObjects); Iterator<ObjectRecord> recordIterator = new MappingIterator<>(batchingIterator, objectRecordConverter::fromEntity); return ResultContainer.<ObjectRecord>builder() .setCount(searchResult.getCount()) .setValues(recordIterator) .build(); } @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 testSearchObjectsWithoutSearchResult() { FactSearchCriteria criteria = createFactSearchCriteria(); when(factSearchManager.searchObjects(criteria)).thenReturn(SearchResult.<ObjectDocument>builder().build()); ResultContainer<ObjectRecord> container = dao.searchObjects(criteria); assertEquals(0, container.getCount()); assertFalse(container.hasNext()); verify(factSearchManager).searchObjects(criteria); verifyNoInteractions(objectManager); }
@Test public void testSearchObjectsWithSearchResult() { UUID id = UUID.randomUUID(); ObjectDocument document = new ObjectDocument().setId(id); ObjectEntity entity = new ObjectEntity().setId(id); ObjectRecord record = new ObjectRecord().setId(id); FactSearchCriteria criteria = createFactSearchCriteria(); when(factSearchManager.searchObjects(criteria)) .thenReturn(SearchResult.<ObjectDocument>builder().setCount(1).addValue(document).build()); when(objectManager.getObjects(anyList())).thenReturn(ListUtils.list(entity).iterator()); when(objectRecordConverter.fromEntity(entity)).thenReturn(record); ResultContainer<ObjectRecord> container = dao.searchObjects(criteria); assertEquals(1, container.getCount()); assertEquals(ListUtils.list(record), ListUtils.list(container)); verify(factSearchManager).searchObjects(criteria); verify(objectManager).getObjects(argThat(list -> list.contains(id))); verify(objectRecordConverter).fromEntity(entity); }