@Test
    void testBasicAuthenticationFailure() throws Exception {
        configureServerWithBasicAuth(bootstrap -> bootstrap
                .register("*", new EchoHandler()));
        final HttpHost target = startServer();

        final TestClient client = client();

        final HttpClientContext context = HttpClientContext.create();
        final CredentialsProvider credsProvider = Mockito.mock(CredentialsProvider.class);
        Mockito.when(credsProvider.getCredentials(Mockito.any(), Mockito.any()))
                .thenReturn(new UsernamePasswordCredentials("test", "all-wrong".toCharArray()));
        context.setCredentialsProvider(credsProvider);
        final HttpGet httpget = new HttpGet("/");

        client.execute(target, httpget, context, response -> {
            final HttpEntity entity = response.getEntity();
            Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
            Assertions.assertNotNull(entity);
            EntityUtils.consume(entity);
            return null;
        });
        Mockito.verify(credsProvider).getCredentials(
                Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
    }
Unit tests for automatic client authentication.
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java