### Question:
ObjectFactDaoFacade implements ObjectFactDao { @Override public FactRecord refreshFact(FactRecord record) { if (record == null) return null; factManager.refreshFact(record.getId()); saveAclEntries(record); saveComments(record); return reindexFact(record.getId()); } @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 testRefreshFactWithNull() { assertNull(dao.refreshFact(null)); }
@Test public void testRefreshFactUpdatesEntity() { FactRecord record = new FactRecord().setId(UUID.randomUUID()); mockReindexingOfFact(record); assertNotNull(dao.refreshFact(record)); verify(factManager).refreshFact(record.getId()); verifyReindexingOfFact(record); }
@Test public void testRefreshFactSavesAclEntry() { FactAclEntryRecord entry = new FactAclEntryRecord(); FactRecord fact = new FactRecord() .setId(UUID.randomUUID()) .addAclEntry(entry); when(factAclEntryRecordConverter.toEntity(entry, fact.getId())).thenReturn(new FactAclEntity()); dao.refreshFact(fact); verify(factManager).saveFactAclEntry(notNull()); verify(factAclEntryRecordConverter).toEntity(entry, fact.getId()); }
@Test public void testRefreshFactFiltersDuplicateAclEntry() { FactAclEntryRecord entry = new FactAclEntryRecord() .setId(UUID.randomUUID()); FactRecord fact = new FactRecord() .setId(UUID.randomUUID()) .addAclEntry(entry); when(factManager.fetchFactAcl(fact.getId())) .thenReturn(ListUtils.list(new FactAclEntity().setId(entry.getId()))); dao.refreshFact(fact); verify(factManager, never()).saveFactAclEntry(any()); verify(factManager).fetchFactAcl(fact.getId()); }
@Test public void testRefreshFactSavesComment() { FactCommentRecord comment = new FactCommentRecord(); FactRecord fact = new FactRecord() .setId(UUID.randomUUID()) .addComment(comment); when(factCommentRecordConverter.toEntity(comment, fact.getId())).thenReturn(new FactCommentEntity()); dao.refreshFact(fact); verify(factManager).saveFactComment(notNull()); verify(factCommentRecordConverter).toEntity(comment, fact.getId()); }
@Test public void testRefreshFactFiltersDuplicateComment() { FactCommentRecord comment = new FactCommentRecord() .setId(UUID.randomUUID()); FactRecord fact = new FactRecord() .setId(UUID.randomUUID()) .addComment(comment); when(factManager.fetchFactComments(fact.getId())) .thenReturn(ListUtils.list(new FactCommentEntity().setId(comment.getId()))); dao.refreshFact(fact); verify(factManager, never()).saveFactComment(any()); verify(factManager).fetchFactComments(fact.getId()); }