### Question:
TransactionalSectionService extends AbstractTransactionalEntityService<Section, SectionDao> implements SectionService { @Override public List<Post> getLastPostsForSection(Section section, int postsCount) { JCUser user = userService.getCurrentUser(); List<Branch> branches = new ArrayList<>(section.getBranches()); List<Long> branchIds = getDao().getAvailableBranchIds(user, branches); return postDao.getLastPostsFor(branchIds, postsCount); } 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 getLastPostsForSectionShouldReturnEmptyListWhenThereIsNoPostsInTheSection() { final int count = 42; JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD); Section section = new Section(SECTION_NAME); when(userService.getCurrentUser()).thenReturn(user); when(sectionDao.getAvailableBranchIds(eq(user), anyList())).thenReturn(Collections.<Long>emptyList()); when(postDao.getLastPostsFor(anyList(), eq(count))).thenReturn(Collections.<Post>emptyList()); List<Post> posts = sectionService.getLastPostsForSection(section, count); assertEquals(posts.size(), 0); }
@Test public void getLastPostsForSectionShouldReturnListOfTheLatestPosts() { final int count = 42; JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD); Section section = new Section(SECTION_NAME); Branch branch1 = new Branch("my branch", "1"); branch1.setId(42); Branch branch2 = new Branch("my branch2", "2"); branch2.setId(43); section.addOrUpdateBranch(branch1); section.addOrUpdateBranch(branch2); when(userService.getCurrentUser()).thenReturn(user); List<Long> branchIds = Arrays.asList(branch1.getId()); when(sectionDao.getAvailableBranchIds(user, section.getBranches())).thenReturn(branchIds); List<Post> posts = new ArrayList<>(); posts.add(new Post(user, "post1")); posts.add(new Post(user, "post2")); when(postDao.getLastPostsFor(branchIds, count)).thenReturn(posts); List<Post> actualPosts = sectionService.getLastPostsForSection(section, count); assertEquals(actualPosts.size(), posts.size()); }