@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.");
}