EntitiesPagedList extends EntitiesList<T> { protected PaginationConstraints buildPaginationConstraints(final int size) { final boolean hasMorePages = hasMorePages(); final boolean isNotFirstPage = currentPage > 1; return new PaginationConstraints() { @Override public boolean isFirstPageEnabled() { return isNotFirstPage; } @Override public boolean isFirstPageVisible() { return isNotFirstPage; } @Override public boolean isPrevPageEnabled() { return isNotFirstPage; } @Override public boolean isPrevPageVisible() { return isNotFirstPage; } @Override public int getCurrentPage() { return currentPage; } @Override public boolean isNextPageEnabled() { return hasMorePages; } @Override public boolean isNextPageVisible() { return hasMorePages; } @Override public boolean isLastPageEnabled() { return hasMorePages; } @Override public boolean isLastPageVisible() { return hasMorePages; } @Override public Integer getTotal() { return size; } }; } @Inject  EntitiesPagedList(LoadingBox loadingBox,
                             View view); void show(final Collection<T> entities,
                     final Callback<T> callback); @Override void clear();  }
@Test public void testCreatePaginationCallbackSinglePage() throws Exception { presenter.totalPages = 1; presenter.currentPage = 1; EntitiesList.PaginationConstraints constraints = presenter.buildPaginationConstraints(10); assertFalse(constraints.isFirstPageEnabled()); assertFalse(constraints.isFirstPageVisible()); assertFalse(constraints.isPrevPageEnabled()); assertFalse(constraints.isPrevPageVisible()); assertFalse(constraints.isNextPageEnabled()); assertFalse(constraints.isNextPageVisible()); assertFalse(constraints.isLastPageEnabled()); assertFalse(constraints.isLastPageVisible()); assertEquals(constraints.getCurrentPage(), 1); }
@Test public void testCreatePaginationCallbackMultiplePages() throws Exception { presenter.totalPages = 5; presenter.currentPage = 2; EntitiesList.PaginationConstraints constraints = presenter.buildPaginationConstraints(10); assertTrue(constraints.isFirstPageEnabled()); assertTrue(constraints.isFirstPageVisible()); assertTrue(constraints.isPrevPageEnabled()); assertTrue(constraints.isPrevPageVisible()); assertTrue(constraints.isNextPageEnabled()); assertTrue(constraints.isNextPageVisible()); assertTrue(constraints.isLastPageEnabled()); assertTrue(constraints.isLastPageVisible()); assertEquals(constraints.getCurrentPage(), 2); }