@Test
public void testTargetAndProxyAuthCaching() throws Exception {

    HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    this.authscheme1.processChallenge(
            new BasicHeader(AUTH.WWW_AUTH, "BASIC realm=auth-realm"));
    this.authscheme2.processChallenge(
            new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
    this.targetState.setAuthScheme(this.authscheme1);
    this.targetState.setCredentials(this.creds1);
    this.targetState.setAuthScope(this.authscope1);
    this.proxyState.setAuthScheme(this.authscheme2);
    this.proxyState.setCredentials(this.creds2);
    this.proxyState.setAuthScope(this.authscope2);
    HttpContext context = new BasicHttpContext();
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, this.proxy);
    context.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);
    HttpResponseInterceptor interceptor = new ResponseAuthCache();
    interceptor.process(response, context);
    AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    Assert.assertNotNull(authCache);
    Assert.assertSame(this.authscheme1, authCache.get(this.target));
    Assert.assertSame(this.authscheme2, authCache.get(this.proxy));
}