@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 testBuildBaseUrlWithNoConfigProperty() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(false);
    when(request.getRequestURL()).thenReturn(new StringBuffer("https://example.com/candlepin"));

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertEquals("https://example.com/candlepin", builder.build().toString());
  }
  @Test
  public void testBuildBaseUrlWithBadUriReturnsNull() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(false);
    when(request.getRequestURL()).thenReturn(new StringBuffer("^$&#**("));

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertNull(builder);
  }
  @Test
  public void testBuildBaseUrlWithNoSchemeProvided() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(true);
    when(config.getString(eq(ConfigProperties.PREFIX_APIURL))).thenReturn("example.com/candlepin");
    when(request.getContextPath()).thenReturn("/candlepin");
    when(request.getRequestURI()).thenReturn("/candlepin/resource");

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertEquals("https://example.com/candlepin/resource", builder.build().toString());
  }