### Question:
PostHibernateDao extends GenericDao<Post> implements PostDao { @Override public List<Post> getLastPostsFor(List<Long> branchIds, int postCount) { return (List<Post>) session() .getNamedQuery("getLastPostsForBranch") .setParameterList("branchIds", branchIds) .setMaxResults(postCount).list(); } PostHibernateDao(SessionFactory sessionFactory); Page<Post> getUserPosts(JCUser author, PageRequest pageRequest, List<Long> allowedBranchesIds); @Override Page<Post> getPosts(Topic topic, PageRequest pageRequest); @Override Post getLastPostFor(Branch branch); @Override List<Post> getLastPostsFor(List<Long> branchIds, int postCount); @Override void changeRating(Long postId, int changes);  }### Answer:
@Test public void getLastPostsForBranchShouldReturnLatestCreatedPosts() { int size = 42; List<Post> posts = PersistedObjectsFactory.createAndSavePostList(size); Topic postsTopic = posts.get(0).getTopic(); Branch postsBranch = postsTopic.getBranch(); ReflectionTestUtils.setField( posts.get(0), "creationDate", new DateTime(2101, 12, 25, 0, 0, 0, 0)); session.save(posts.get(0)); ReflectionTestUtils.setField( posts.get(1), "creationDate", new DateTime(2100, 12, 25, 0, 0, 0, 0)); session.save(posts.get(1)); List<Post> actualLastPosts = dao.getLastPostsFor(Arrays.asList(postsBranch.getId()), 2); assertEquals(actualLastPosts.size(), 2); assertEquals(actualLastPosts.get(0).getId(), posts.get(0).getId()); assertEquals(actualLastPosts.get(1).getId(), posts.get(1).getId()); }
@Test public void getLastPostsInEmptyBranchShouldReturnEmptyList() { Topic topic = PersistedObjectsFactory.getDefaultTopic(); Branch branch = topic.getBranch(); branch.deleteTopic(topic); session.save(branch); assertTrue(dao.getLastPostsFor(Arrays.asList(branch.getId()), 42).isEmpty(), "The branch is empty, so last posts mustn't be found"); }