@Test public void setItem() { pg.setItems(123); // 13页 pg.setItem(122); assertEquals(13, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(12, pg.getPreviousPage()); assertEquals(3, pg.getPreviousPage(10)); assertEquals(13, pg.getNextPage()); assertEquals(13, pg.getNextPage(10)); assertEquals(121, pg.getBeginIndex()); assertEquals(123, pg.getEndIndex()); assertEquals(120, pg.getOffset()); assertEquals(3, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertFalse(pg.isDisabledPage(1)); assertFalse(pg.isDisabledPage(2)); assertFalse(pg.isDisabledPage(11)); assertTrue(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); // 1页 pg.setItem(0); assertEquals(1, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(1, pg.getPreviousPage()); assertEquals(1, pg.getPreviousPage(10)); assertEquals(2, pg.getNextPage()); assertEquals(11, pg.getNextPage(10)); assertEquals(13, pg.getLastPage()); assertEquals(1, pg.getBeginIndex()); assertEquals(10, pg.getEndIndex()); assertEquals(0, pg.getOffset()); assertEquals(10, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertTrue(pg.isDisabledPage(1)); assertFalse(pg.isDisabledPage(2)); assertFalse(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); }
/** 测试有限多项。 */ @Test public void limitedItems() { pg.setItems(123); assertEquals(13, pg.getPages()); assertEquals(123, pg.getItems()); assertEquals(10, pg.getItemsPerPage()); // 初始状态,第1页 assertEquals(1, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(1, pg.getPreviousPage()); assertEquals(1, pg.getPreviousPage(10)); assertEquals(2, pg.getNextPage()); assertEquals(11, pg.getNextPage(10)); assertEquals(13, pg.getLastPage()); assertEquals(1, pg.getBeginIndex()); assertEquals(10, pg.getEndIndex()); assertEquals(0, pg.getOffset()); assertEquals(10, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertTrue(pg.isDisabledPage(1)); assertFalse(pg.isDisabledPage(2)); assertFalse(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); // 下一页,第2页 pg.setPage(2); assertEquals(2, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(1, pg.getPreviousPage()); assertEquals(1, pg.getPreviousPage(10)); assertEquals(3, pg.getNextPage()); assertEquals(12, pg.getNextPage(10)); assertEquals(11, pg.getBeginIndex()); assertEquals(20, pg.getEndIndex()); assertEquals(10, pg.getOffset()); assertEquals(10, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertFalse(pg.isDisabledPage(1)); assertTrue(pg.isDisabledPage(2)); assertFalse(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); // 第11页 pg.setPage(11); assertEquals(11, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(10, pg.getPreviousPage()); assertEquals(1, pg.getPreviousPage(10)); assertEquals(12, pg.getNextPage()); assertEquals(13, pg.getNextPage(10)); assertEquals(101, pg.getBeginIndex()); assertEquals(110, pg.getEndIndex()); assertEquals(100, pg.getOffset()); assertEquals(10, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertFalse(pg.isDisabledPage(1)); assertFalse(pg.isDisabledPage(2)); assertTrue(pg.isDisabledPage(11)); assertFalse(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); // 第13页(最后一页) pg.setPage(13); assertEquals(13, pg.getPage()); assertEquals(1, pg.getFirstPage()); assertEquals(12, pg.getPreviousPage()); assertEquals(3, pg.getPreviousPage(10)); assertEquals(13, pg.getNextPage()); assertEquals(13, pg.getNextPage(10)); assertEquals(121, pg.getBeginIndex()); assertEquals(123, pg.getEndIndex()); assertEquals(120, pg.getOffset()); assertEquals(3, pg.getLength()); assertTrue(pg.isDisabledPage(0)); assertFalse(pg.isDisabledPage(1)); assertFalse(pg.isDisabledPage(2)); assertFalse(pg.isDisabledPage(11)); assertTrue(pg.isDisabledPage(13)); assertTrue(pg.isDisabledPage(14)); }