@Test
  public void testPostProcessWithPaging() {
    when(page.getPageRequest()).thenReturn(pageRequest);
    when(page.getMaxRecords()).thenReturn(15);
    when(pageRequest.isPaging()).thenReturn(true);
    when(pageRequest.getPage()).thenReturn(2);
    when(pageRequest.getPerPage()).thenReturn(5);

    // We're going to take the quick path through buildBaseUrl.
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(false);
    when(request.getRequestURL()).thenReturn(new StringBuffer("https://example.com/candlepin"));
    when(request.getQueryString()).thenReturn("order=asc&page=1&per_page=10");

    MultivaluedMap<String, Object> map = new MultivaluedMapImpl<String, Object>();
    when(response.getMetadata()).thenReturn(map);

    ResteasyProviderFactory.pushContext(Page.class, page);
    ResteasyProviderFactory.pushContext(HttpServletRequest.class, request);

    interceptor.postProcess(response);
    String header = (String) map.getFirst(LinkHeaderPostInterceptor.LINK_HEADER);

    // It would be a bit much to parse the entire header, so let's just make
    // sure that we have first, last, next, and prev links.
    assertTrue(header.contains("rel=\"first\""));
    assertTrue(header.contains("rel=\"last\""));
    assertTrue(header.contains("rel=\"next\""));
    assertTrue(header.contains("rel=\"prev\""));
  }
  @Test
  public void testGetLastPageWhenEvenlyDivisible() {
    Page 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));
  }
  @Test
  public void testGetLastPageWhenMaxRecordsLessThanLimit() {
    Page 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 testGetNextPageWhenNoNextAvailable() {
    Page p = new Page();
    p.setMaxRecords(55);

    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);

    pr.setPerPage(10);
    pr.setPage(6);

    assertNull(interceptor.getNextPage(p));
  }
  @Test
  public void testGetNextPage() {
    Page p = new Page();
    p.setMaxRecords(55);

    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);

    pr.setPerPage(10);
    pr.setPage(3);

    assertEquals(Integer.valueOf(4), interceptor.getNextPage(p));
  }
  @Test
  public void testGetPrevPageWhenOnFirstPage() {
    Page p = new Page();
    p.setMaxRecords(55);

    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);

    pr.setPerPage(10);
    pr.setPage(1);

    assertNull(interceptor.getPrevPage(p));
  }
  @Test
  public void testPagesWithOutOfBoundsInitialPage() {
    Page p = new Page();
    p.setMaxRecords(8);

    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);

    pr.setPerPage(10);
    pr.setPage(2);

    assertNull(interceptor.getPrevPage(p));
    assertNull(interceptor.getNextPage(p));
    assertEquals(Integer.valueOf(1), interceptor.getLastPage(p));
  }
 @Test
 public void testPostProcessWithNonPagingPresentation() {
   when(page.getPageRequest()).thenReturn(pageRequest);
   when(pageRequest.isPaging()).thenReturn(false);
   ResteasyProviderFactory.pushContext(Page.class, page);
   interceptor.postProcess(response);
   verify(page, times(2)).getPageRequest();
   verify(pageRequest).isPaging();
 }