@Test
    void testAuthenticationTargetAsProxy() throws Exception {
        configureServer(bootstrap -> bootstrap
                .register("*", new ProxyAuthHandler()));
        final HttpHost target = startServer();

        final TestClient client = client();

        final HttpClientContext context = HttpClientContext.create();
        final CredentialsProvider credsProvider = Mockito.mock(CredentialsProvider.class);
        context.setCredentialsProvider(credsProvider);

        final HttpGet httpget = new HttpGet("/");
        client.execute(target, httpget, context, response -> {
            final HttpEntity entity = response.getEntity();
            Assertions.assertEquals(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, response.getCode());
            EntityUtils.consume(entity);
            return null;
        });
    }
Unit tests for automatic client authentication.
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java