LinkHeaderResponseFilter implements ContainerResponseFilter { protected Integer getLastPage(Page<?> page) { PageRequest pageRequest = page.getPageRequest(); int lastPage = page.getMaxRecords() / pageRequest.getPerPage(); if (page.getMaxRecords() % pageRequest.getPerPage() != 0) { lastPage++; } return lastPage; } @Inject  LinkHeaderResponseFilter(Configuration config,
        @Named("PREFIX_APIURL_KEY") String apiUrlPrefixKey); @SuppressWarnings("rawtypes") void filter(ContainerRequestContext reqContext, ContainerResponseContext respContext); static final int MAX_LINK_LENGTH; static final String LINK_HEADER; static final String TOTAL_RECORDS_COUNT; static final String LINK_TYPE; }
@Test public void testGetLastPage() { Page<Object> p = new Page<>(); p.setMaxRecords(55); PageRequest pr = new PageRequest(); p.setPageRequest(pr); pr.setPerPage(10); pr.setPage(1); assertEquals(Integer.valueOf(6), interceptor.getLastPage(p)); }
@Test public void testGetLastPageWhenMaxRecordsLessThanLimit() { Page<Object> p = new Page<>(); p.setMaxRecords(8); PageRequest pr = new PageRequest(); p.setPageRequest(pr); pr.setPerPage(10); pr.setPage(1); assertEquals(Integer.valueOf(1), interceptor.getLastPage(p)); }
@Test public void testGetLastPageWhenEvenlyDivisible() { Page<Object> p = new Page<>(); p.setMaxRecords(10); PageRequest pr = new PageRequest(); p.setPageRequest(pr); pr.setPerPage(10); pr.setPage(1); assertEquals(Integer.valueOf(1), interceptor.getLastPage(p)); }