PaginationInfo { public static Map<String, Object> createAttributeMap(int pageIndex, int size, Sort sort) { Map<String, Object> attr = new HashMap<String, Object>(3); attr.put(PAGE_ATTR, pageIndex); attr.put(SIZE_ATTR, size); if (sort != null) { Iterator<Order> orders = sort.iterator(); if (orders.hasNext()) { Order order = orders.next(); attr.put(SORT_ORDER_PROPERTY_ATTR, order.getProperty()); attr.put(SORT_ORDER_DIRECTION_ATTR, order.getDirection() .toString()); } } return attr; } 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 testCreateAttributeMap_SortNull() { int page = 1; int size = 1; Map<String, Object> attributesMap = PaginationInfo.createAttributeMap( page, size, null); assertThat(Integer.valueOf(attributesMap.get("page").toString()), is( page)); assertThat(Integer.valueOf(attributesMap.get("size").toString()), is( size)); assertThat(attributesMap.get("sortOrderProperty"), is(nullValue())); assertThat(attributesMap.get("sortOrderDirection"), is(nullValue())); }
@Test public void testCreateAttributeMap_SortSet() { int page = 1; int size = 1; Sort mockedSort = Sort.by(Direction.DESC, "id"); Map<String, Object> attributesMap = PaginationInfo.createAttributeMap( page, size, mockedSort); assertThat(Integer.valueOf(attributesMap.get("page").toString()), is( page)); assertThat(Integer.valueOf(attributesMap.get("size").toString()), is( size)); assertThat(attributesMap.get("sortOrderProperty").toString(), is("id")); assertThat(attributesMap.get("sortOrderDirection").toString(), is( "DESC")); }
@Test public void testCreateAttributeMapfail() { int page = 1; int size = 1; Sort sort = mock(Sort.class); @SuppressWarnings("unchecked") Iterator<Order> orders = mock(Iterator.class); when(sort.iterator()).thenReturn(orders); when(orders.hasNext()).thenReturn(false); Map<String, Object> attributesMap = PaginationInfo.createAttributeMap( page, size, sort); assertThat(Integer.valueOf(attributesMap.get("page").toString()), is( page)); assertThat(Integer.valueOf(attributesMap.get("size").toString()), is( size)); assertThat(attributesMap.get("sortOrderProperty"), is(nullValue())); assertThat(attributesMap.get("sortOrderDirection"), is(nullValue())); }