### Question:
TransactionalSectionService extends AbstractTransactionalEntityService<Section, SectionDao> implements SectionService { @Override public List<Section> getAllAvailableSections(long currentTopicId) { List<Section> result = new ArrayList<>(); Topic topic = topicDao.get(currentTopicId); List<Section> sections = this.getDao().getAll(); JCUser user = userService.getCurrentUser(); for (Section section : sections) { List<Branch> branches = new ArrayList<>(section.getBranches()); for (Branch branch : branches) { if (branch.equals(topic.getBranch())) { branches.remove(branch); break; } } if (getDao().getCountAvailableBranches(user, branches) > 0) { result.add(section); } } return result; } TransactionalSectionService(SectionDao dao, BranchService branchService, UserService userService,
                                       TopicDao topicDao, PostDao postDao); @Override List<Section> getAll(); @Override List<Section> getAllAvailableSections(long currentTopicId); void prepareSectionsForView(List<Section> sections); @Override Section deleteAllTopicsInSection(long sectionId); @Override void deleteAllTopicsInForum(); @Override void ifSectionIsVisible(Section section); @Override List<Post> getLastPostsForSection(Section section, int postsCount);  }### Answer:
@Test public void getAllAvailableSections() { JCUser user = ObjectsFactory.getDefaultUser(); Topic topic = ObjectsFactory.getTopic(user, 1); org.jtalks.jcommune.model.entity.Branch topicBranch = ObjectsFactory.getDefaultBranchWithTopic(100L, topic); Section sectionWithAvaliableBranches = ObjectsFactory.getDefaultSectionWithBranches(); List<Section> allSections = new ArrayList<>(); allSections.add(ObjectsFactory.getDefaultSection()); allSections.add(ObjectsFactory.getDefaultSectionWithBranch(topicBranch)); allSections.add(sectionWithAvaliableBranches); List<Section> expectedSections = new ArrayList<>(); expectedSections.add(sectionWithAvaliableBranches); when(sectionDao.getAll()).thenReturn(allSections); when(topicDao.get(TOPIC_ID)).thenReturn(topic); when(userService.getCurrentUser()).thenReturn(user); when(sectionDao.getCountAvailableBranches(user, new ArrayList<Branch>())).thenReturn(0L); when(sectionDao.getCountAvailableBranches(user, sectionWithAvaliableBranches.getBranches())).thenReturn(3L); List<Section> actualSectionList = sectionService.getAllAvailableSections(TOPIC_ID); assertEquals(actualSectionList, expectedSections, "Should return all available sections."); }