### Question:
TransactionalBranchService extends AbstractTransactionalEntityService<Branch, BranchDao> implements BranchService, PluginBranchService { @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") public <T extends JtalksPermission> List<Group> getPermissionGroupsFor(long componentId, long branchId, boolean allowed, T permission) throws NotFoundException { GroupsPermissions allPermissions = permissionService.getPermissionsFor(get(branchId)); if (allowed) { return allPermissions.getAllowed(permission); } return allPermissions.getRestricted(permission); } 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(expectedExceptions = NotFoundException.class) public void getPermissionGroupsShouldThrowExceptionWhenBranchDoesNotExist() throws Exception { when(branchDao.isExist(42L)).thenReturn(false); branchService.getPermissionGroupsFor(0, 42L, true, BranchPermission.CLOSE_TOPICS); }