### Question:
TopicHibernateDao extends GenericDao<Topic> implements TopicDao { @Override public Page<Topic> getTopics(Branch branch, PageRequest pageRequest) { int totalCount = countTopics(branch); Query query = session().getNamedQuery("getTopicsInBranch") .setParameter(BRANCH, branch); pageRequest.adjustPageNumber(totalCount); query = query.setFirstResult(pageRequest.getOffset()) .setMaxResults(pageRequest.getPageSize()); @SuppressWarnings(UNCHECKED) List<Topic> topics = (List<Topic>) query.list(); return new PageImpl<Topic>(topics, pageRequest, totalCount); } 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 testGetTopicsWithEnabledPaging() { int totalSize = 50; int pageCount = 2; int pageSize = totalSize / pageCount; PageRequest pageRequest = new PageRequest("1", pageSize); List<Topic> topicList = PersistedObjectsFactory.createAndSaveTopicList(totalSize); Branch branch = topicList.get(0).getBranch(); Page<Topic> topicsPage = dao.getTopics(branch, pageRequest); assertThat("Incorrect pagination", topicsPage, hasPages()); }
@Test public void testGetTopicsWithEnabledPagingPageTooLow() { int totalSize = 50; int pageCount = 2; int pageSize = totalSize / pageCount; PageRequest pageRequest = new PageRequest("0", pageSize); List<Topic> topicList = PersistedObjectsFactory.createAndSaveTopicList(totalSize); Branch branch = topicList.get(0).getBranch(); Page<Topic> topicsPage = dao.getTopics(branch, pageRequest); assertThat("Incorrect pagination", topicsPage, hasPages()); assertEquals(topicsPage.getNumber(), 1); }
@Test public void testGetTopicsWithEnabledPagingTooBigg() { int totalSize = 50; int pageCount = 2; int pageSize = totalSize / pageCount; PageRequest pageRequest = new PageRequest("1000", pageSize); List<Topic> topicList = PersistedObjectsFactory.createAndSaveTopicList(totalSize); Branch branch = topicList.get(0).getBranch(); Page<Topic> topicsPage = dao.getTopics(branch, pageRequest); assertThat("Incorrect pagination", topicsPage, hasPages()); assertEquals(topicsPage.getNumber(), pageCount); }