### Question:
LastReadPostHibernateDao extends GenericDao<LastReadPost> implements LastReadPostDao { @Override @SuppressWarnings("unchecked") public List<LastReadPost> getLastReadPosts(JCUser forWho, List<Topic> sourceTopics) { if (!sourceTopics.isEmpty()) { return (List<LastReadPost>) session().getNamedQuery("getLastReadPostsInTopicsForUser") .setParameterList("sourceTopics", sourceTopics) .setParameter("user", forWho) .list(); } return Collections.emptyList(); } LastReadPostHibernateDao(SessionFactory sessionFactory); @Override @SuppressWarnings("unchecked") List<LastReadPost> getLastReadPostsInTopic(Topic topic); @Override LastReadPost getLastReadPost(JCUser forWho, Topic topic); @Override @SuppressWarnings("unchecked") List<LastReadPost> getLastReadPosts(JCUser forWho, List<Topic> sourceTopics); @Override void deleteLastReadPostsFor(JCUser user);  }### Answer:
@Test public void testDeleteMarksTopicsToUser() { List<Topic> topics = PersistedObjectsFactory.createAndSaveTopicListWithPosts(10); JCUser user = PersistedObjectsFactory.getDefaultUser(); SQLQuery deletedEntities = (SQLQuery) session.getNamedQuery("deleteAllMarksReadToUser"); deletedEntities .addSynchronizedEntityClass(LastReadPost.class) .setParameter("user", user.getId()) .setParameter("branch", topics.get(0).getBranch().getId()) .setCacheable(false) .executeUpdate(); List<LastReadPost> lastReadPostList = lastReadPostDao.getLastReadPosts(user, topics); assertTrue(lastReadPostList.isEmpty()); }
@Test public void getLastReadPostsForUserInTopicsShouldReturnThem() { int topicsSize = 10; JCUser user = PersistedObjectsFactory.getDefaultUser(); List<Topic> userTopics = PersistedObjectsFactory.createAndSaveTopicListWithPosts(topicsSize); markAllTopicsASRead(userTopics, user); List<LastReadPost> lastReadPosts = lastReadPostDao.getLastReadPosts(user, userTopics); assertEquals(lastReadPosts.size(), topicsSize, "For every passed topic it should return last read post."); }
@Test public void getLastReadPostsForUserShouldReturnEmptyListForEmptyListOfTopics() { List<Topic> userTopics = Collections.emptyList(); JCUser user = new JCUser("user", "user@gmail.com", "password"); List<LastReadPost> lastReadPosts = lastReadPostDao.getLastReadPosts(user, userTopics); assertTrue(lastReadPosts.isEmpty(), "For passed empty list of topics it should return empty list."); }