### Question:
TransactionalSectionService extends AbstractTransactionalEntityService<Section, SectionDao> implements SectionService { @Override public Section deleteAllTopicsInSection(long sectionId) throws NotFoundException { Section section = get(sectionId); List<Branch> loopList = new ArrayList<>(section.getBranches()); for (Branch branch : loopList) { branchService.deleteAllTopics(branch.getId()); } logger.info("All branches for sections \"{}\" were deleted. " + "Section id: {}", section.getName(), section.getId()); return section; } 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 testDeleteAllBranches() throws NotFoundException { Section expectedSection = new Section(SECTION_NAME); expectedSection.addOrUpdateBranch(new Branch(null, null)); expectedSection.addOrUpdateBranch(new Branch(null, null)); when(sectionDao.isExist(SECTION_ID)).thenReturn(true); when(sectionDao.get(SECTION_ID)).thenReturn(expectedSection); Section actualSection = sectionService.deleteAllTopicsInSection(SECTION_ID); assertEquals(actualSection, expectedSection, "Sections aren't equals"); verify(sectionDao).isExist(SECTION_ID); verify(sectionDao).get(SECTION_ID); }
@Test public void testDeleteAllBranchesInEmptySection() throws NotFoundException { Section expectedSection = new Section(SECTION_NAME); when(sectionDao.isExist(SECTION_ID)).thenReturn(true); when(sectionDao.get(SECTION_ID)).thenReturn(expectedSection); Section actualSection = sectionService.deleteAllTopicsInSection(SECTION_ID); assertEquals(actualSection, expectedSection, "Sections aren't equals"); verify(sectionDao).isExist(SECTION_ID); verify(sectionDao).get(SECTION_ID); }
@Test(expectedExceptions=NotFoundException.class) public void testDeleteAllBranchesWithIncorrectId() throws NotFoundException { when(sectionDao.isExist(SECTION_ID)).thenReturn(false); sectionService.deleteAllTopicsInSection(SECTION_ID); assertTrue(false); }