@Test
    void testNextNonceUsageFromContext() throws Exception {
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        final HttpHost host = new HttpHost("somehost", 80);
        final CredentialsProvider credentialsProvider = CredentialsProviderBuilder.create()
                .add(new AuthScope(host, "realm1", null), "username", "password".toCharArray())
                .build();

        final HttpClientContext context = HttpClientContext.create();
        context.setNextNonce("sampleNextNonce"); // Set `nextNonce` in the context

        final DigestScheme authscheme = new DigestScheme();
        final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"initialNonce\"";
        final AuthChallenge authChallenge = parse(challenge);
        authscheme.processChallenge(authChallenge, context);

        // Simulate credentials validation and generate auth response
        authscheme.isResponseReady(host, credentialsProvider, context);
        final String authResponse = authscheme.generateAuthResponse(host, request, context);

        // Validate that `sampleNextNonce` (from context) is used in place of the initial nonce
        final Map<String, String> paramMap = parseAuthResponse(authResponse);
        Assertions.assertEquals("sampleNextNonce", paramMap.get("nonce"), "The nonce should match 'auth-nextnonce' from the context.");

        // Verify that `auth-nextnonce` was removed from context after use
        Assertions.assertNull(context.getAttribute("auth-nextnonce"), "The next nonce should be removed from the context after use.");
    }
Test digest authentication with unknown qop value
httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestDigestScheme.java