### Question:
TopicHibernateDao extends GenericDao<Topic> implements TopicDao { @Override public Page<Topic> getUnansweredTopics(PageRequest pageRequest, JCUser user) { if (!user.isAnonymous()) { return getUnansweredTopicsByGroupIds(getGroupIds(user), pageRequest); } return getUnansweredTopicsForAnonymousUser(pageRequest); } TopicHibernateDao(SessionFactory sessionFactory); @Override Page<Topic> getTopicsUpdatedSince(DateTime timeStamp, PageRequest pageRequest, JCUser user); @Override Page<Topic> getUnansweredTopics(PageRequest pageRequest, JCUser user); @Override Topic getLastUpdatedTopicInBranch(Branch branch); @Override Page<Topic> getTopics(Branch branch, PageRequest pageRequest); @Override int countTopics(Branch branch); @Override Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity); @Override List<Long> getForbiddenBranchesIds(JCUser user); @Override List<Long> getAllowedBranchesIds(JCUser user);  }### Answer:
@Test public void testGetUnansweredTopicsForRegisteredUsers() { JCUser user = createAndSaveBranchesWithUnansweredTopics(); PageRequest pageRequest = new PageRequest("1", 2); Page<Topic> result = dao.getUnansweredTopics(pageRequest, user); assertEquals(result.getContent().size(), 2); assertEquals(result.getTotalElements(), 2); }
@Test public void testGetUnansweredTopicsForAnonymousUsers() { createAndSaveBranchesWithUnansweredTopics(); PageRequest pageRequest = new PageRequest("1", 2); Page<Topic> result = dao.getUnansweredTopics(pageRequest, new AnonymousUser()); assertEquals(result.getContent().size(), 2); assertEquals(result.getTotalElements(), 2); }
@Test public void testGetUnansweredTopicsWithPaging() { JCUser user = createAndSaveBranchesWithUnansweredTopics(); PageRequest pageRequest = new PageRequest("2", 1); Page<Topic> result = dao.getUnansweredTopics(pageRequest, user); assertEquals(result.getContent().size(), 1); assertEquals(result.getTotalElements(), 2); }
@Test public void testGetUnansweredTopicsWithPagingPageTooLow() { JCUser user = createAndSaveBranchesWithUnansweredTopics(); PageRequest pageRequest = new PageRequest("0", 1); Page<Topic> result = dao.getUnansweredTopics(pageRequest, user); assertEquals(result.getContent().size(), 1); assertEquals(result.getTotalElements(), 2); assertEquals(result.getNumber(), 1); }
@Test public void testGetUnansweredTopicsWithPagingPageTooBig() { JCUser user = createAndSaveBranchesWithUnansweredTopics(); PageRequest pageRequest = new PageRequest("1000", 1); Page<Topic> result = dao.getUnansweredTopics(pageRequest, user); assertEquals(result.getContent().size(), 1); assertEquals(result.getTotalElements(), 2); assertEquals(result.getNumber(), 2); }