PaginationInfo { public BeginAndEnd getBeginAndEnd() { int begin = Math.max(0, current - maxDisplayCount / 2); int end = begin + (maxDisplayCount - 1); if (end > page.getTotalPages() - 1) { end = page.getTotalPages() - 1; begin = Math.max(0, end - (maxDisplayCount - 1)); } return new BeginAndEnd(begin, end); } PaginationInfo(Page<?> page, String pathTmpl, String queryTmpl,
            int maxDisplayCount);  PaginationInfo(Page<?> page, String pathTmpl, String queryTmpl,
            String criteriaQuery, boolean disableHtmlEscapeOfCriteriaQuery,
            int maxDisplayCount); static Map<String, Object> createAttributeMap(int pageIndex,
            int size, Sort sort); int getCurrent(); String getPathTmpl(); String getQueryTmpl(); String getCriteriaQuery(); int getMaxDisplayCount(); String getPageUrl(int pageIndex); String getFirstUrl(); String getLastUrl(); String getPreviousUrl(); String getNextUrl(); boolean isFirstPage(); boolean isLastPage(); boolean isCurrent(int page); BeginAndEnd getBeginAndEnd(); static final int DEFAULT_MAX_DISPLAY_COUNT; static final String DEFAULT_PATH_TEMPLATE; static final String DEFAULT_QUERY_TEMPLATE; static final String PAGE_ATTR; static final String SIZE_ATTR; static final String SORT_ORDER_PROPERTY_ATTR; static final String SORT_ORDER_DIRECTION_ATTR; static final String A_ELM; static final String HREF_ATTR; static final String CLASS_ATTR; static final String DEFAULT_OUTER_ELM; static final String DEFAULT_OUTER_CLASS; static final String DEFAULT_INNER_ELM; static final String DEFAULT_INNER_CLASS; static final String DEFAULT_FIRST_LINK_TEXT; static final String DEFAULT_PREVIOUS_LINK_TEXT; static final String DEFAULT_NEXT_LINK_TEXT; static final String DEFAULT_LAST_LINK_TEXT; static final String DEFAULT_DISABLED_HREF; static final String DEFAULT_ACTIVE_CLASS; static final String DEFAULT_DISABLED_CLASS; }
@Test public void testGetBeginAndEnd_totalPagesIsSmallerThanMaxDisplayCount() { int maxDisplayCount = 10; PaginationInfo info = new PaginationInfo(page, pathTmpl, queryTmpl, maxDisplayCount); BeginAndEnd endNumBig = info.getBeginAndEnd(); assertThat(endNumBig.getBegin(), is(0)); assertThat(endNumBig.getEnd(), is(6)); }
@Test public void testGetBeginAndEnd_totalPagesIsGreaterThanMaxDisplayCount() { int maxDisplayCount = 3; PaginationInfo info = new PaginationInfo(page, pathTmpl, queryTmpl, maxDisplayCount); BeginAndEnd endNumBig = info.getBeginAndEnd(); assertThat(endNumBig.getBegin(), is(4)); assertThat(endNumBig.getEnd(), is(6)); }
@Test public void testGetBeginAndEnd_maxDisplayCountIsZero() { int maxDisplayCount = 0; PaginationInfo info = new PaginationInfo(page, pathTmpl, queryTmpl, maxDisplayCount); BeginAndEnd endNumBig = info.getBeginAndEnd(); assertThat(endNumBig.getBegin(), is(5)); assertThat(endNumBig.getEnd(), is(4)); }