### Question:
TransactionalTopicFetchService extends AbstractTransactionalEntityService<Topic, TopicDao> implements TopicFetchService, PluginTopicFetchService { @Override public Topic get(Long id) throws NotFoundException { Topic topic = super.get(id); topic.setViews(topic.getViews() + 1); this.getDao().saveOrUpdate(topic); return topic; } TransactionalTopicFetchService(TopicDao dao, ComponentService componentService, UserService userService, TopicSearchDao searchDao); @Override Topic get(Long id); @Override Page<Topic> getRecentTopics(String page); @Override Page<Topic> getUnansweredTopics(String page); @Override Topic getTopicSilently(Long id); @Override Page<Topic> getTopics(Branch branch, String page); @Override Page<Topic> searchByTitleAndContent(String phrase, String page); @Override void rebuildSearchIndex(); @PreAuthorize("hasPermission(#branchId, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") @Override void checkViewTopicPermission(Long branchId);  }### Answer:
@Test public void testGetTopic() throws NotFoundException { Topic expectedTopic = new Topic(user, "title"); when(topicDao.isExist(999L)).thenReturn(true); when(topicDao.get(999L)).thenReturn(expectedTopic); int viewsCount = expectedTopic.getViews(); Topic actualTopic = topicFetchService.get(999L); assertEquals(actualTopic.getViews(), viewsCount + 1); assertEquals(actualTopic, expectedTopic, "Topics aren't equal"); verify(topicDao).isExist(999L); verify(topicDao).get(999L); }
@Test(expectedExceptions = {NotFoundException.class}) public void testGetTopicWithIncorrectId() throws NotFoundException { when(topicDao.isExist(333L)).thenReturn(false); topicFetchService.get(333L); }