### Question:
TransactionalBranchService extends AbstractTransactionalEntityService<Branch, BranchDao> implements BranchService, PluginBranchService { @Override public List<Branch> getAvailableBranchesInSection(long sectionId, long currentTopicId) throws NotFoundException { if (!sectionDao.isExist(sectionId)) { throw new NotFoundException("Section with id: " + sectionId + " not found"); } Section section = sectionDao.get(sectionId); List<Branch> branches = (List) section.getBranches(); return getBranchesWithViewPermission(currentTopicId, branches); } TransactionalBranchService(
            BranchDao branchDao,
            SectionDao sectionDao,
            TopicDao topicDao,
            GroupDao groupDao,
            TopicModificationService topicService,
            PermissionService permissionService,
            BranchLastPostService lastPostService); @Override @PreAuthorize("hasPermission(#branchId, 'BRANCH', 'BranchPermission.VIEW_TOPICS') " + "or hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") Branch getBranchOfComponent(long componentId, long branchId); @Override List<Branch> getAllAvailableBranches(long currentTopicId); @Override List<Branch> getAvailableBranchesInSection(long sectionId, long currentTopicId); @Override void fillStatisticInfo(List<org.jtalks.common.model.entity.Branch> branches); @Override @PreAuthorize("hasPermission(#id, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") Branch get(Long id); @Override Branch deleteAllTopics(long branchId); @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") void changeBranchInfo(long componentId, long branchId, String title, String description); @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") void createNewBranch(long componentId, long sectionId, String title, String description); @Override void checkIfBranchExists(long branchId); @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") GroupsPermissions getPermissionsFor(long componentId, long branchId); @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") List<Group> getPermissionGroupsFor(long componentId, long branchId, boolean allowed, T permission); @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") void changeBranchPermissions(long componentId, long branchId, boolean allowed, PermissionChanges changes);  }### Answer:
@Test public void getAvailableBranchesInSectionShouldRemoveTopicBranch() throws NotFoundException { setUpGetAvailableBranchesInSection(); for (org.jtalks.common.model.entity.Branch branch : section.getBranches()) { when(permissionService.hasBranchPermission(branch.getId(), BranchPermission.VIEW_TOPICS)).thenReturn(true); } List<Branch> result = branchService.getAvailableBranchesInSection(SECTION_ID, TOPIC_ID); assertFalse(result.contains(topic.getBranch()), "Topic shouldn't be accessible for move to the same branch."); }
@Test(expectedExceptions = {NotFoundException.class}) public void getAvailableBranchesInSectionWithIncorrectSectionId() throws NotFoundException { when(sectionDao.isExist(SECTION_ID)).thenReturn(false); branchService.getAvailableBranchesInSection(SECTION_ID, TOPIC_ID); }