### Question:
TransactionalSectionService extends AbstractTransactionalEntityService<Section, SectionDao> implements SectionService { @Override public void ifSectionIsVisible(Section section) throws AccessDeniedException { List<Branch> branches = section.getBranches(); if (getDao().getCountAvailableBranches(userService.getCurrentUser(), branches) == 0) { throw new AccessDeniedException("Access denied to view for section " + section.getId()); } } 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(expectedExceptions = AccessDeniedException.class) public void testCheckAccessForVisibleException()throws AccessDeniedException{ JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD); List<Branch> branches = new ArrayList<>(); Section section = new Section(SECTION_NAME); when(userService.getCurrentUser()).thenReturn(user); when(sectionDao.getCountAvailableBranches(user,branches)).thenReturn(0L); sectionService.ifSectionIsVisible(section); }
@Test public void testCheckAccessForVisibleNoException()throws AccessDeniedException{ JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD); List<Branch> branches = new ArrayList<>(); Section section = new Section(SECTION_NAME); when(userService.getCurrentUser()).thenReturn(user); when(sectionDao.getCountAvailableBranches(user,branches)).thenReturn(1L); sectionService.ifSectionIsVisible(section); }