Just FYI on the commit comment, the Java diamond operator is Java 7 not 8.

Gary

On Tue, Apr 27, 2021, 07:13 <[email protected]> wrote:

> This is an automated email from the ASF dual-hosted git repository.
>
> olegk pushed a commit to branch 5.2.x
> in repository
> https://gitbox.apache.org/repos/asf/httpcomponents-client.git
>
> commit 3bb88a74d2f2336dcf47df37e46dc64da19a55e0
> Author: Oleg Kalnichevski <[email protected]>
> AuthorDate: Sun Dec 20 15:22:42 2020 +0100
>
>     Java 1.8 upgrade
> ---
>  .../hc/client5/http/cache/HttpCacheEntry.java      |   2 +-
>  .../AbstractSerializingAsyncCacheStorage.java      |   2 +-
>  .../client5/http/impl/cache/AsyncCachingExec.java  | 154 +++------
>  .../http/impl/cache/BasicHttpAsyncCache.java       |  19 +-
>  .../hc/client5/http/impl/cache/BasicHttpCache.java |  19 +-
>  .../client5/http/impl/cache/BasicIdGenerator.java  |   2 +-
>  .../hc/client5/http/impl/cache/CachingExec.java    |  20 +-
>  .../impl/cache/CachingH2AsyncClientBuilder.java    |  20 +-
>  .../impl/cache/CachingHttpAsyncClientBuilder.java  |  20 +-
>  .../http/impl/cache/CachingHttpClientBuilder.java  |  20 +-
>  .../impl/cache/DefaultAsyncCacheInvalidator.java   |   2 +-
>  .../impl/cache/DefaultAsyncCacheRevalidator.java   |  99 +++---
>  .../http/impl/cache/DefaultCacheRevalidator.java   |  41 +--
>  .../hc/client5/http/impl/cache/WarningValue.java   |   4 +-
>  .../memcached/MemcachedHttpAsyncCacheStorage.java  |  62 ++--
>  .../hc/client5/http/cache/TestHttpCacheEntry.java  |   2 +-
>  .../http/impl/cache/AbstractProtocolTest.java      |   2 +-
>  .../TestAbstractSerializingAsyncCacheStorage.java  | 336
> ++++++-------------
>  .../cache/TestAbstractSerializingCacheStorage.java |  95 ++----
>  .../cache/TestCachedHttpResponseGenerator.java     |   2 +-
>  .../client5/http/impl/cache/TestCachingExec.java   |   2 +-
>  .../impl/cache/TestConditionalRequestBuilder.java  |  10 +-
>  .../cache/TestDefaultAsyncCacheInvalidator.java    |  37 +-
>  .../impl/cache/TestDefaultCacheInvalidator.java    |  22 +-
>  .../memcached/TestPrefixKeyHashingScheme.java      |   9 +-
>  .../org/apache/hc/client5/http/fluent/Request.java |   2 +-
>  .../examples/fluent/FluentResponseHandling.java    |  58 ++--
>  .../AbstractHttpAsyncClientAuthentication.java     | 182 ++--------
>  .../async/AbstractHttpAsyncFundamentalsTest.java   |  19 +-
>  .../async/AbstractHttpAsyncRedirectsTest.java      | 372
> ++++++---------------
>  .../AbstractHttpReactiveFundamentalsTest.java      |  19 +-
>  .../testing/async/AbstractServerTestBase.java      |  32 +-
>  .../testing/async/TestHttp1AsyncRedirects.java     |  47 +--
>  .../TestHttp1AsyncStatefulConnManagement.java      |  63 +---
>  .../async/TestHttp1ClientAuthentication.java       |  25 +-
>  .../hc/client5/testing/fluent/TestFluent.java      |  63 +---
>  .../testing/sync/TestClientAuthentication.java     |  74 +---
>  .../testing/sync/TestClientRequestExecution.java   |  13 +-
>  .../testing/sync/TestCookieVirtualHost.java        |  87 ++---
>  .../testing/sync/TestMalformedServerResponse.java  |  29 +-
>  .../hc/client5/testing/sync/TestRedirects.java     | 328
> +++++-------------
>  .../client5/testing/sync/TestSSLSocketFactory.java |  40 +--
>  .../testing/sync/TestStatefulConnManagement.java   |  21 +-
>  .../testing/sync/TestWindowsNegotiateScheme.java   |  31 +-
>  .../apache/hc/client5/http/entity/mime/Header.java |   6 +-
>  .../client5/http/impl/IdleConnectionEvictor.java   |  25 +-
>  .../apache/hc/client5/http/impl/Operations.java    |  18 +-
>  .../impl/async/AbstractHttpAsyncClientBase.java    |   8 +-
>  .../http/impl/async/AsyncExecChainElement.java     |  14 +-
>  .../http/impl/async/H2AsyncClientBuilder.java      |  76 +----
>  .../http/impl/async/HttpAsyncClientBuilder.java    |  59 +---
>  .../client5/http/impl/async/HttpAsyncClients.java  |  23 +-
>  .../async/InternalAbstractHttpAsyncClient.java     | 302 ++++++++---------
>  .../impl/async/InternalHttpAsyncExecRuntime.java   |   9 +-
>  .../async/LoggingAsyncClientExchangeHandler.java   |  52 ++-
>  .../http/impl/async/MinimalH2AsyncClient.java      | 243 ++++++--------
>  .../http/impl/async/MinimalHttpAsyncClient.java    | 292 ++++++++--------
>  .../hc/client5/http/impl/auth/NTLMEngineImpl.java  |   2 +-
>  .../http/impl/classic/AIMDBackoffManager.java      |  12 +-
>  .../http/impl/classic/ExecChainElement.java        |  11 +-
>  .../http/impl/classic/HttpClientBuilder.java       |  31 +-
>  .../http/impl/classic/ResponseEntityProxy.java     |  19 +-
>  .../http/impl/cookie/LaxExpiresHandler.java        |   2 +-
>  .../http/impl/cookie/RFC6265CookieSpec.java        |   2 +-
>  .../nio/PoolingAsyncClientConnectionManager.java   |  18 +-
>  .../http/socket/PlainConnectionSocketFactory.java  |   9 +-
>  .../http/ssl/AbstractClientTlsStrategy.java        |  75 ++---
>  .../client5/http/ssl/ClientTlsStrategyBuilder.java |  13 +-
>  .../http/ssl/ConscryptClientTlsStrategy.java       |   2 +-
>  .../apache/hc/client5/http/ssl/HttpsSupport.java   |   9 +-
>  .../http/ssl/SSLConnectionSocketFactory.java       |   9 +-
>  .../http/entity/TestDecompressingEntity.java       |  10 +-
>  .../http/examples/AsyncClientCustomSSL.java        |  15 +-
>  .../http/examples/AsyncClientH2ServerPush.java     |  55 ++-
>  .../http/examples/AsyncClientInterceptors.java     |  38 +--
>  .../http/examples/AsyncClientMessageTrailers.java  |  31 +-
>  .../hc/client5/http/examples/ClientCustomSSL.java  |  15 +-
>  .../client5/http/examples/ClientInterceptors.java  |  27 +-
>  .../http/examples/ClientWithRequestFuture.java     |  11 +-
>  .../http/examples/ClientWithResponseHandler.java   |  29 +-
>  .../examples/ReactiveClientFullDuplexExchange.java |  21 +-
>  .../http/impl/classic/MockConnPoolControl.java     |   4 +-
>  .../client5/http/impl/classic/TestConnectExec.java |  25 +-
>  .../classic/TestFutureRequestExecutionService.java |  35 +-
>  .../classic/TestHttpClientBuilderInterceptors.java |  39 +--
>  .../impl/classic/TestHttpRequestRetryExec.java     |  44 +--
>  .../http/impl/classic/TestMainClientExec.java      |  23 +-
>  .../http/impl/classic/TestProtocolExec.java        |  18 +-
>  .../http/impl/routing/TestRouteTracker.java        |  40 +--
>  .../hc/client5/http/routing/TestHttpRoute.java     |  21 +-
>  pom.xml                                            |   4 +-
>  91 files changed, 1385 insertions(+), 2969 deletions(-)
>
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheEntry.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheEntry.java
> index ff53120..8d071d6 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheEntry.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheEntry.java
> @@ -124,7 +124,7 @@ public class HttpCacheEntry implements MessageHeaders,
> Serializable {
>       */
>      public HttpCacheEntry(final Date requestDate, final Date
> responseDate, final int status,
>              final Header[] responseHeaders, final Resource resource) {
> -        this(requestDate, responseDate, status, responseHeaders,
> resource, new HashMap<String,String>());
> +        this(requestDate, responseDate, status, responseHeaders,
> resource, new HashMap<>());
>      }
>
>      /**
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
> index 0263a6d..126192b 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
> @@ -187,7 +187,7 @@ public abstract class
> AbstractSerializingAsyncCacheStorage<T, CAS> implements Ht
>
>                                  @Override
>                                  public void completed(final Boolean
> result) {
> -                                    if (result) {
> +                                    if (result.booleanValue()) {
>                                          callback.completed(result);
>                                      } else {
>                                          if
> (!complexCancellable.isCancelled()) {
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
> index 93419a7..c9001b2 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
> @@ -57,7 +57,6 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
>  import org.apache.hc.core5.concurrent.CancellableDependency;
>  import org.apache.hc.core5.concurrent.ComplexFuture;
>  import org.apache.hc.core5.concurrent.FutureCallback;
> -import org.apache.hc.core5.function.Factory;
>  import org.apache.hc.core5.http.ContentType;
>  import org.apache.hc.core5.http.EntityDetails;
>  import org.apache.hc.core5.http.Header;
> @@ -102,14 +101,8 @@ class AsyncCachingExec extends CachingExecBase
> implements AsyncExecChainHandler
>          super(config);
>          this.responseCache = Args.notNull(cache, "Response cache");
>          this.cacheRevalidator = cacheRevalidator;
> -        this.conditionalRequestBuilder = new
> ConditionalRequestBuilder<>(new Factory<HttpRequest, HttpRequest>() {
> -
> -            @Override
> -            public HttpRequest create(final HttpRequest request) {
> -                return BasicRequestBuilder.copy(request).build();
> -            }
> -
> -        });
> +        this.conditionalRequestBuilder = new
> ConditionalRequestBuilder<>(request ->
> +                BasicRequestBuilder.copy(request).build());
>      }
>
>      AsyncCachingExec(
> @@ -675,14 +668,7 @@ class AsyncCachingExec extends CachingExecBase
> implements AsyncExecChainHandler
>                      cacheRevalidator.revalidateCacheEntry(
>                              responseCache.generateKey(target, request,
> entry),
>                              asyncExecCallback,
> -                            new
> DefaultAsyncCacheRevalidator.RevalidationCall() {
> -
> -                                @Override
> -                                public void execute(final
> AsyncExecCallback asyncExecCallback) {
> -                                    revalidateCacheEntry(target, request,
> entityProducer, fork, chain, asyncExecCallback, entry);
> -                                }
> -
> -                            });
> +                            asyncExecCallback1 ->
> revalidateCacheEntry(target, request, entityProducer, fork, chain,
> asyncExecCallback1, entry));
>                      triggerResponse(cacheResponse, scope,
> asyncExecCallback);
>                  } catch (final ResourceIOException ex) {
>                      asyncExecCallback.failed(ex);
> @@ -771,26 +757,12 @@ class AsyncCachingExec extends CachingExecBase
> implements AsyncExecChainHandler
>                      recordCacheUpdate(scope.clientContext);
>                  }
>                  if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
> -                    return new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                        @Override
> -                        public void run() {
> -
> triggerUpdatedCacheEntryResponse(backendResponse, responseDate);
> -                        }
> -
> -                    });
> +                    return new
> AsyncExecCallbackWrapper(asyncExecCallback, () ->
> triggerUpdatedCacheEntryResponse(backendResponse, responseDate));
>                  }
>                  if (staleIfErrorAppliesTo(statusCode)
>                          && !staleResponseNotAllowed(request, cacheEntry,
> getCurrentDate())
>                          && validityPolicy.mayReturnStaleIfError(request,
> cacheEntry, responseDate)) {
> -                    return new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                        @Override
> -                        public void run() {
> -                            triggerResponseStaleCacheEntry();
> -                        }
> -
> -                    });
> +                    return new
> AsyncExecCallbackWrapper(asyncExecCallback,
> this::triggerResponseStaleCacheEntry);
>                  }
>                  return new BackendResponseHandler(target,
> conditionalRequest, requestDate, responseDate, scope, asyncExecCallback);
>              }
> @@ -809,57 +781,49 @@ class AsyncCachingExec extends CachingExecBase
> implements AsyncExecChainHandler
>                      final HttpRequest unconditional =
> conditionalRequestBuilder.buildUnconditionalRequest(
>
>  BasicRequestBuilder.copy(scope.originalRequest).build());
>
> -                    callback1 = new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> +                    callback1 = new
> AsyncExecCallbackWrapper(asyncExecCallback, () ->
> chainProceed(unconditional, entityProducer, scope, chain, new
> AsyncExecCallback() {
>
>                          @Override
> -                        public void run() {
> -                            chainProceed(unconditional, entityProducer,
> scope, chain, new AsyncExecCallback() {
> -
> -                                @Override
> -                                public AsyncDataConsumer handleResponse(
> -                                        final HttpResponse
> backendResponse2,
> -                                        final EntityDetails
> entityDetails) throws HttpException, IOException {
> -                                    final Date responseDate2 =
> getCurrentDate();
> -                                    final AsyncExecCallback callback2 =
> evaluateResponse(backendResponse2, responseDate2);
> -                                    callbackRef.set(callback2);
> -                                    return
> callback2.handleResponse(backendResponse2, entityDetails);
> -                                }
> -
> -                                @Override
> -                                public void
> handleInformationResponse(final HttpResponse response) throws
> HttpException, IOException {
> -                                    final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> -                                    if (callback2 != null) {
> -
> callback2.handleInformationResponse(response);
> -                                    } else {
> -
> asyncExecCallback.handleInformationResponse(response);
> -                                    }
> -                                }
> -
> -                                @Override
> -                                public void completed() {
> -                                    final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> -                                    if (callback2 != null) {
> -                                        callback2.completed();
> -                                    } else {
> -                                        asyncExecCallback.completed();
> -                                    }
> -                                }
> +                        public AsyncDataConsumer handleResponse(
> +                                final HttpResponse backendResponse2,
> +                                final EntityDetails entityDetails1)
> throws HttpException, IOException {
> +                            final Date responseDate2 = getCurrentDate();
> +                            final AsyncExecCallback callback2 =
> evaluateResponse(backendResponse2, responseDate2);
> +                            callbackRef.set(callback2);
> +                            return
> callback2.handleResponse(backendResponse2, entityDetails1);
> +                        }
>
> -                                @Override
> -                                public void failed(final Exception cause)
> {
> -                                    final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> -                                    if (callback2 != null) {
> -                                        callback2.failed(cause);
> -                                    } else {
> -                                        asyncExecCallback.failed(cause);
> -                                    }
> -                                }
> +                        @Override
> +                        public void handleInformationResponse(final
> HttpResponse response) throws HttpException, IOException {
> +                            final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> +                            if (callback2 != null) {
> +
> callback2.handleInformationResponse(response);
> +                            } else {
> +
> asyncExecCallback.handleInformationResponse(response);
> +                            }
> +                        }
>
> -                            });
> +                        @Override
> +                        public void completed() {
> +                            final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> +                            if (callback2 != null) {
> +                                callback2.completed();
> +                            } else {
> +                                asyncExecCallback.completed();
> +                            }
> +                        }
>
> +                        @Override
> +                        public void failed(final Exception cause) {
> +                            final AsyncExecCallback callback2 =
> callbackRef.getAndSet(null);
> +                            if (callback2 != null) {
> +                                callback2.failed(cause);
> +                            } else {
> +                                asyncExecCallback.failed(cause);
> +                            }
>                          }
>
> -                    });
> +                    }));
>                  } else {
>                      callback1 = evaluateResponse(backendResponse1,
> responseDate1);
>                  }
> @@ -1036,49 +1000,21 @@ class AsyncCachingExec extends CachingExecBase
> implements AsyncExecChainHandler
>                      final Header resultEtagHeader =
> backendResponse.getFirstHeader(HeaderConstants.ETAG);
>                      if (resultEtagHeader == null) {
>                          LOG.warn("304 response did not contain ETag");
> -                        callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                            @Override
> -                            public void run() {
> -                                callBackend(target, request,
> entityProducer, scope, chain, asyncExecCallback);
> -                            }
> -
> -                        });
> +                        callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, () -> callBackend(target,
> request, entityProducer, scope, chain, asyncExecCallback));
>                      } else {
>                          final String resultEtag =
> resultEtagHeader.getValue();
>                          final Variant matchingVariant =
> variants.get(resultEtag);
>                          if (matchingVariant == null) {
>                              LOG.debug("304 response did not contain ETag
> matching one sent in If-None-Match");
> -                            callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                                @Override
> -                                public void run() {
> -                                    callBackend(target, request,
> entityProducer, scope, chain, asyncExecCallback);
> -                                }
> -
> -                            });
> +                            callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, () -> callBackend(target,
> request, entityProducer, scope, chain, asyncExecCallback));
>                          } else {
>                              if
> (revalidationResponseIsTooOld(backendResponse, matchingVariant.getEntry()))
> {
>                                  final HttpRequest unconditional =
> conditionalRequestBuilder.buildUnconditionalRequest(
>
>  BasicRequestBuilder.copy(request).build());
>
>  scope.clientContext.setAttribute(HttpCoreContext.HTTP_REQUEST,
> unconditional);
> -                                callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                                    @Override
> -                                    public void run() {
> -                                        callBackend(target, request,
> entityProducer, scope, chain, asyncExecCallback);
> -                                    }
> -
> -                                });
> +                                callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, () -> callBackend(target,
> request, entityProducer, scope, chain, asyncExecCallback));
>                              } else {
> -                                callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
> -
> -                                    @Override
> -                                    public void run() {
> -
> updateVariantCacheEntry(backendResponse, responseDate, matchingVariant);
> -                                    }
> -
> -                                });
> +                                callback = new
> AsyncExecCallbackWrapper(asyncExecCallback, () ->
> updateVariantCacheEntry(backendResponse, responseDate, matchingVariant));
>                              }
>                          }
>                      }
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
> index 7ba4040..e3bf75b 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
> @@ -34,7 +34,6 @@ import java.util.Set;
>  import org.apache.hc.client5.http.cache.HeaderConstants;
>  import org.apache.hc.client5.http.cache.HttpAsyncCacheInvalidator;
>  import org.apache.hc.client5.http.cache.HttpAsyncCacheStorage;
> -import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
>  import org.apache.hc.client5.http.cache.HttpCacheEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheUpdateException;
>  import org.apache.hc.client5.http.cache.ResourceFactory;
> @@ -211,14 +210,7 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
>              @Override
>              public void completed(final Boolean result) {
>                  storage.updateEntry(cacheKey,
> -                        new HttpCacheCASOperation() {
> -
> -                            @Override
> -                            public HttpCacheEntry execute(final
> HttpCacheEntry existing) throws ResourceIOException {
> -                                return
> cacheUpdateHandler.updateParentCacheEntry(req.getRequestUri(), existing,
> entry, variantKey, variantCacheKey);
> -                            }
> -
> -                        },
> +                        existing ->
> cacheUpdateHandler.updateParentCacheEntry(req.getRequestUri(), existing,
> entry, variantKey, variantCacheKey),
>                          new FutureCallback<Boolean>() {
>
>                              @Override
> @@ -280,14 +272,7 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
>          final String variantKey =
> cacheKeyGenerator.generateVariantKey(request, entry);
>          final String variantCacheKey = variant.getCacheKey();
>          return storage.updateEntry(cacheKey,
> -                new HttpCacheCASOperation() {
> -
> -                    @Override
> -                    public HttpCacheEntry execute(final HttpCacheEntry
> existing) throws ResourceIOException {
> -                        return
> cacheUpdateHandler.updateParentCacheEntry(request.getRequestUri(),
> existing, entry, variantKey, variantCacheKey);
> -                    }
> -
> -                },
> +                existing ->
> cacheUpdateHandler.updateParentCacheEntry(request.getRequestUri(),
> existing, entry, variantKey, variantCacheKey),
>                  new FutureCallback<Boolean>() {
>
>                      @Override
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
> index 11125d0..70e5272 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
> @@ -31,7 +31,6 @@ import java.util.HashMap;
>  import java.util.Map;
>
>  import org.apache.hc.client5.http.cache.HeaderConstants;
> -import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
>  import org.apache.hc.client5.http.cache.HttpCacheEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheInvalidator;
>  import org.apache.hc.client5.http.cache.HttpCacheStorage;
> @@ -163,14 +162,7 @@ class BasicHttpCache implements HttpCache {
>          final String variantCacheKey =
> cacheKeyGenerator.generateKey(host, req, entry);
>          storeEntry(variantCacheKey, entry);
>          try {
> -            storage.updateEntry(cacheKey, new HttpCacheCASOperation() {
> -
> -                @Override
> -                public HttpCacheEntry execute(final HttpCacheEntry
> existing) throws ResourceIOException {
> -                    return
> cacheUpdateHandler.updateParentCacheEntry(req.getRequestUri(), existing,
> entry, variantKey, variantCacheKey);
> -                }
> -
> -            });
> +            storage.updateEntry(cacheKey, existing ->
> cacheUpdateHandler.updateParentCacheEntry(req.getRequestUri(), existing,
> entry, variantKey, variantCacheKey));
>          } catch (final HttpCacheUpdateException ex) {
>              if (LOG.isWarnEnabled()) {
>                  LOG.warn("Cannot update cache entry with key {}",
> cacheKey);
> @@ -194,14 +186,7 @@ class BasicHttpCache implements HttpCache {
>          final String variantCacheKey = variant.getCacheKey();
>
>          try {
> -            storage.updateEntry(cacheKey, new HttpCacheCASOperation() {
> -
> -                @Override
> -                public HttpCacheEntry execute(final HttpCacheEntry
> existing) throws ResourceIOException {
> -                    return
> cacheUpdateHandler.updateParentCacheEntry(request.getRequestUri(),
> existing, entry, variantKey, variantCacheKey);
> -                }
> -
> -            });
> +            storage.updateEntry(cacheKey, existing ->
> cacheUpdateHandler.updateParentCacheEntry(request.getRequestUri(),
> existing, entry, variantKey, variantCacheKey));
>          } catch (final HttpCacheUpdateException ex) {
>              if (LOG.isWarnEnabled()) {
>                  LOG.warn("Cannot update cache entry with key {}",
> cacheKey);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicIdGenerator.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicIdGenerator.java
> index 80fdb6b..c49a36a 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicIdGenerator.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicIdGenerator.java
> @@ -66,7 +66,7 @@ class BasicIdGenerator {
>          buffer.append(System.currentTimeMillis());
>          buffer.append('.');
>          final Formatter formatter = new Formatter(buffer, Locale.ROOT);
> -        formatter.format("%1$016x-%2$08x", Long.valueOf(this.count),
> Integer.valueOf(rndnum));
> +        formatter.format("%1$016x-%2$08x", this.count, rndnum);
>          formatter.close();
>          buffer.append('.');
>          buffer.append(this.hostname);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
> index fa702e0..f2e4125 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
> @@ -48,7 +48,6 @@ import org.apache.hc.client5.http.impl.ExecSupport;
>  import org.apache.hc.client5.http.protocol.HttpClientContext;
>  import org.apache.hc.client5.http.schedule.SchedulingStrategy;
>  import org.apache.hc.client5.http.utils.DateUtils;
> -import org.apache.hc.core5.function.Factory;
>  import org.apache.hc.core5.http.ClassicHttpRequest;
>  import org.apache.hc.core5.http.ClassicHttpResponse;
>  import org.apache.hc.core5.http.Header;
> @@ -111,14 +110,8 @@ class CachingExec extends CachingExecBase implements
> ExecChainHandler {
>          super(config);
>          this.responseCache = Args.notNull(cache, "Response cache");
>          this.cacheRevalidator = cacheRevalidator;
> -        this.conditionalRequestBuilder = new
> ConditionalRequestBuilder<>(new Factory<ClassicHttpRequest,
> ClassicHttpRequest>() {
> -
> -            @Override
> -            public ClassicHttpRequest create(final ClassicHttpRequest
> classicHttpRequest) {
> -                return
> ClassicRequestBuilder.copy(classicHttpRequest).build();
> -            }
> -
> -        });
> +        this.conditionalRequestBuilder = new
> ConditionalRequestBuilder<>(classicHttpRequest ->
> +
> ClassicRequestBuilder.copy(classicHttpRequest).build());
>      }
>
>      CachingExec(
> @@ -290,14 +283,7 @@ class CachingExec extends CachingExecBase implements
> ExecChainHandler {
>                      final SimpleHttpResponse response =
> generateCachedResponse(request, context, entry, now);
>                      cacheRevalidator.revalidateCacheEntry(
>                              responseCache.generateKey(target, request,
> entry),
> -                            new
> DefaultCacheRevalidator.RevalidationCall() {
> -
> -                        @Override
> -                        public ClassicHttpResponse execute() throws
> HttpException, IOException {
> -                            return revalidateCacheEntry(target, request,
> fork, chain, entry);
> -                        }
> -
> -                    });
> +                            () -> revalidateCacheEntry(target, request,
> fork, chain, entry));
>                      return convert(response, scope);
>                  }
>                  return revalidateCacheEntry(target, request, scope,
> chain, entry);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingH2AsyncClientBuilder.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingH2AsyncClientBuilder.java
> index e8b4b50..f468cfe 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingH2AsyncClientBuilder.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingH2AsyncClientBuilder.java
> @@ -26,9 +26,7 @@
>   */
>  package org.apache.hc.client5.http.impl.cache;
>
> -import java.io.Closeable;
>  import java.io.File;
> -import java.io.IOException;
>  import java.util.concurrent.ScheduledExecutorService;
>  import java.util.concurrent.ScheduledThreadPoolExecutor;
>
> @@ -130,14 +128,7 @@ public class CachingH2AsyncClientBuilder extends
> H2AsyncClientBuilder {
>              } else {
>                  final ManagedHttpCacheStorage managedStorage = new
> ManagedHttpCacheStorage(config);
>                  if (this.deleteCache) {
> -                    addCloseable(new Closeable() {
> -
> -                        @Override
> -                        public void close() throws IOException {
> -                            managedStorage.shutdown();
> -                        }
> -
> -                    });
> +                    addCloseable(managedStorage::shutdown);
>                  } else {
>                      addCloseable(managedStorage);
>                  }
> @@ -153,14 +144,7 @@ public class CachingH2AsyncClientBuilder extends
> H2AsyncClientBuilder {
>          DefaultAsyncCacheRevalidator cacheRevalidator = null;
>          if (config.getAsynchronousWorkers() > 0) {
>              final ScheduledExecutorService executorService = new
> ScheduledThreadPoolExecutor(config.getAsynchronousWorkers());
> -            addCloseable(new Closeable() {
> -
> -                @Override
> -                public void close() throws IOException {
> -                    executorService.shutdownNow();
> -                }
> -
> -            });
> +            addCloseable(executorService::shutdownNow);
>              cacheRevalidator = new DefaultAsyncCacheRevalidator(
>                      executorService,
>                      this.schedulingStrategy != null ?
> this.schedulingStrategy : ImmediateSchedulingStrategy.INSTANCE);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpAsyncClientBuilder.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpAsyncClientBuilder.java
> index fe92f61..15dbe7c 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpAsyncClientBuilder.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpAsyncClientBuilder.java
> @@ -26,9 +26,7 @@
>   */
>  package org.apache.hc.client5.http.impl.cache;
>
> -import java.io.Closeable;
>  import java.io.File;
> -import java.io.IOException;
>  import java.util.concurrent.ScheduledExecutorService;
>  import java.util.concurrent.ScheduledThreadPoolExecutor;
>
> @@ -130,14 +128,7 @@ public class CachingHttpAsyncClientBuilder extends
> HttpAsyncClientBuilder {
>              } else {
>                  final ManagedHttpCacheStorage managedStorage = new
> ManagedHttpCacheStorage(config);
>                  if (this.deleteCache) {
> -                    addCloseable(new Closeable() {
> -
> -                        @Override
> -                        public void close() throws IOException {
> -                            managedStorage.shutdown();
> -                        }
> -
> -                    });
> +                    addCloseable(managedStorage::shutdown);
>                  } else {
>                      addCloseable(managedStorage);
>                  }
> @@ -153,14 +144,7 @@ public class CachingHttpAsyncClientBuilder extends
> HttpAsyncClientBuilder {
>          DefaultAsyncCacheRevalidator cacheRevalidator = null;
>          if (config.getAsynchronousWorkers() > 0) {
>              final ScheduledExecutorService executorService = new
> ScheduledThreadPoolExecutor(config.getAsynchronousWorkers());
> -            addCloseable(new Closeable() {
> -
> -                @Override
> -                public void close() throws IOException {
> -                    executorService.shutdownNow();
> -                }
> -
> -            });
> +            addCloseable(executorService::shutdownNow);
>              cacheRevalidator = new DefaultAsyncCacheRevalidator(
>                      executorService,
>                      this.schedulingStrategy != null ?
> this.schedulingStrategy : ImmediateSchedulingStrategy.INSTANCE);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
> index 5d6bf91..f2b1e51 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
> @@ -26,9 +26,7 @@
>   */
>  package org.apache.hc.client5.http.impl.cache;
>
> -import java.io.Closeable;
>  import java.io.File;
> -import java.io.IOException;
>  import java.util.concurrent.ScheduledExecutorService;
>  import java.util.concurrent.ScheduledThreadPoolExecutor;
>
> @@ -122,14 +120,7 @@ public class CachingHttpClientBuilder extends
> HttpClientBuilder {
>              } else {
>                  final ManagedHttpCacheStorage managedStorage = new
> ManagedHttpCacheStorage(config);
>                  if (this.deleteCache) {
> -                    addCloseable(new Closeable() {
> -
> -                        @Override
> -                        public void close() throws IOException {
> -                            managedStorage.shutdown();
> -                        }
> -
> -                    });
> +                    addCloseable(managedStorage::shutdown);
>                  } else {
>                      addCloseable(managedStorage);
>                  }
> @@ -145,14 +136,7 @@ public class CachingHttpClientBuilder extends
> HttpClientBuilder {
>          DefaultCacheRevalidator cacheRevalidator = null;
>          if (config.getAsynchronousWorkers() > 0) {
>              final ScheduledExecutorService executorService = new
> ScheduledThreadPoolExecutor(config.getAsynchronousWorkers());
> -            addCloseable(new Closeable() {
> -
> -                @Override
> -                public void close() throws IOException {
> -                    executorService.shutdownNow();
> -                }
> -
> -            });
> +            addCloseable(executorService::shutdownNow);
>              cacheRevalidator = new DefaultCacheRevalidator(
>                      executorService,
>                      this.schedulingStrategy != null ?
> this.schedulingStrategy : ImmediateSchedulingStrategy.INSTANCE);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
> index 4a57479..77b720b 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
> @@ -70,7 +70,7 @@ public class DefaultAsyncCacheInvalidator extends
> CacheInvalidatorBase implement
>              @Override
>              public void completed(final Boolean result) {
>                  if (LOG.isDebugEnabled()) {
> -                    if (result) {
> +                    if (result.booleanValue()) {
>                          LOG.debug("Cache entry with key {} successfully
> flushed", cacheKey);
>                      } else {
>                          LOG.debug("Cache entry with key {} could not be
> flushed", cacheKey);
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java
> index 90718d8..43fab11 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java
> @@ -118,59 +118,52 @@ class DefaultAsyncCacheRevalidator extends
> CacheRevalidatorBase {
>              final String cacheKey ,
>              final AsyncExecCallback asyncExecCallback,
>              final RevalidationCall call) {
> -        scheduleRevalidation(cacheKey, new Runnable() {
> -
> -                        @Override
> -                        public void run() {
> -                            call.execute(new AsyncExecCallback() {
> -
> -                                private final
> AtomicReference<HttpResponse> responseRef = new AtomicReference<>(null);
> -
> -                                @Override
> -                                public AsyncDataConsumer handleResponse(
> -                                        final HttpResponse response,
> -                                        final EntityDetails
> entityDetails) throws HttpException, IOException {
> -                                    responseRef.set(response);
> -                                    return
> asyncExecCallback.handleResponse(response, entityDetails);
> -                                }
> -
> -                                @Override
> -                                public void handleInformationResponse(
> -                                        final HttpResponse response)
> throws HttpException, IOException {
> -
> asyncExecCallback.handleInformationResponse(response);
> -                                }
> -
> -                                @Override
> -                                public void completed() {
> -                                    final HttpResponse httpResponse =
> responseRef.getAndSet(null);
> -                                    if (httpResponse != null &&
> httpResponse.getCode() < HttpStatus.SC_SERVER_ERROR &&
> !isStale(httpResponse)) {
> -                                        jobSuccessful(cacheKey);
> -                                    } else {
> -                                        jobFailed(cacheKey);
> -                                    }
> -                                    asyncExecCallback.completed();
> -                                }
> -
> -                                @Override
> -                                public void failed(final Exception cause)
> {
> -                                    if (cause instanceof IOException) {
> -                                        LOG.debug("Asynchronous
> revalidation failed due to I/O error", cause);
> -                                    } else if (cause instanceof
> HttpException) {
> -                                        LOG.error("HTTP protocol
> exception during asynchronous revalidation", cause);
> -                                    } else {
> -                                        LOG.error("Unexpected runtime
> exception thrown during asynchronous revalidation", cause);
> -                                    }
> -                                    try {
> -                                        jobFailed(cacheKey);
> -                                    } finally {
> -                                        asyncExecCallback.failed(cause);
> -                                    }
> -                                }
> -
> -                            });
> -                        }
> -
> -                    });
> +        scheduleRevalidation(cacheKey, () -> call.execute(new
> AsyncExecCallback() {
> +
> +            private final AtomicReference<HttpResponse> responseRef = new
> AtomicReference<>(null);
> +
> +            @Override
> +            public AsyncDataConsumer handleResponse(
> +                    final HttpResponse response,
> +                    final EntityDetails entityDetails) throws
> HttpException, IOException {
> +                responseRef.set(response);
> +                return asyncExecCallback.handleResponse(response,
> entityDetails);
> +            }
> +
> +            @Override
> +            public void handleInformationResponse(
> +                    final HttpResponse response) throws HttpException,
> IOException {
> +                asyncExecCallback.handleInformationResponse(response);
> +            }
> +
> +            @Override
> +            public void completed() {
> +                final HttpResponse httpResponse =
> responseRef.getAndSet(null);
> +                if (httpResponse != null && httpResponse.getCode() <
> HttpStatus.SC_SERVER_ERROR && !isStale(httpResponse)) {
> +                    jobSuccessful(cacheKey);
> +                } else {
> +                    jobFailed(cacheKey);
> +                }
> +                asyncExecCallback.completed();
> +            }
> +
> +            @Override
> +            public void failed(final Exception cause) {
> +                if (cause instanceof IOException) {
> +                    LOG.debug("Asynchronous revalidation failed due to
> I/O error", cause);
> +                } else if (cause instanceof HttpException) {
> +                    LOG.error("HTTP protocol exception during
> asynchronous revalidation", cause);
> +                } else {
> +                    LOG.error("Unexpected runtime exception thrown during
> asynchronous revalidation", cause);
> +                }
> +                try {
> +                    jobFailed(cacheKey);
> +                } finally {
> +                    asyncExecCallback.failed(cause);
> +                }
> +            }
> +
> +        }));
>      }
>
>  }
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheRevalidator.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheRevalidator.java
> index 514b904..b4846aa 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheRevalidator.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheRevalidator.java
> @@ -75,30 +75,25 @@ class DefaultCacheRevalidator extends
> CacheRevalidatorBase {
>      public void revalidateCacheEntry(
>              final String cacheKey,
>              final RevalidationCall call) {
> -        scheduleRevalidation(cacheKey, new Runnable() {
> +        scheduleRevalidation(cacheKey, () -> {
> +            try (ClassicHttpResponse httpResponse = call.execute()) {
> +                if (httpResponse.getCode() < HttpStatus.SC_SERVER_ERROR
> && !isStale(httpResponse)) {
> +                    jobSuccessful(cacheKey);
> +                } else {
> +                    jobFailed(cacheKey);
> +                }
> +            } catch (final IOException ex) {
> +                jobFailed(cacheKey);
> +                LOG.debug("Asynchronous revalidation failed due to I/O
> error", ex);
> +            } catch (final HttpException ex) {
> +                jobFailed(cacheKey);
> +                LOG.error("HTTP protocol exception during asynchronous
> revalidation", ex);
> +            } catch (final RuntimeException ex) {
> +                jobFailed(cacheKey);
> +                LOG.error("Unexpected runtime exception thrown during
> asynchronous revalidation", ex);
> +            }
>
> -                        @Override
> -                        public void run() {
> -                            try (ClassicHttpResponse httpResponse =
> call.execute()) {
> -                                if (httpResponse.getCode() <
> HttpStatus.SC_SERVER_ERROR && !isStale(httpResponse)) {
> -                                    jobSuccessful(cacheKey);
> -                                } else {
> -                                    jobFailed(cacheKey);
> -                                }
> -                            } catch (final IOException ex) {
> -                                jobFailed(cacheKey);
> -                                LOG.debug("Asynchronous revalidation
> failed due to I/O error", ex);
> -                            } catch (final HttpException ex) {
> -                                jobFailed(cacheKey);
> -                                LOG.error("HTTP protocol exception during
> asynchronous revalidation", ex);
> -                            } catch (final RuntimeException ex) {
> -                                jobFailed(cacheKey);
> -                                LOG.error("Unexpected runtime exception
> thrown during asynchronous revalidation", ex);
> -                            }
> -
> -                        }
> -
> -                    });
> +        });
>      }
>
>  }
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/WarningValue.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/WarningValue.java
> index 70747cf..905cf86 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/WarningValue.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/WarningValue.java
> @@ -358,10 +358,10 @@ class WarningValue {
>      @Override
>      public String toString() {
>          if (warnDate != null) {
> -            return String.format("%d %s %s \"%s\"",
> Integer.valueOf(warnCode),
> +            return String.format("%d %s %s \"%s\"", warnCode,
>                      warnAgent, warnText, DateUtils.formatDate(warnDate));
>          } else {
> -            return String.format("%d %s %s", Integer.valueOf(warnCode),
> warnAgent, warnText);
> +            return String.format("%d %s %s", warnCode, warnAgent,
> warnText);
>          }
>      }
>
> diff --git
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpAsyncCacheStorage.java
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpAsyncCacheStorage.java
> index 36d075c..b49d63f 100644
> ---
> a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpAsyncCacheStorage.java
> +++
> b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpAsyncCacheStorage.java
> @@ -47,11 +47,7 @@ import net.spy.memcached.CASResponse;
>  import net.spy.memcached.CASValue;
>  import net.spy.memcached.MemcachedClient;
>  import net.spy.memcached.internal.BulkFuture;
> -import net.spy.memcached.internal.BulkGetCompletionListener;
> -import net.spy.memcached.internal.BulkGetFuture;
> -import net.spy.memcached.internal.GetCompletionListener;
>  import net.spy.memcached.internal.GetFuture;
> -import net.spy.memcached.internal.OperationCompletionListener;
>  import net.spy.memcached.internal.OperationFuture;
>
>  /**
> @@ -160,21 +156,16 @@ public class MemcachedHttpAsyncCacheStorage extends
> AbstractBinaryAsyncCacheStor
>      }
>
>      private <T> Cancellable operation(final OperationFuture<T>
> operationFuture, final FutureCallback<T> callback) {
> -        operationFuture.addListener(new OperationCompletionListener() {
> -
> -            @Override
> -            public void onComplete(final OperationFuture<?> future)
> throws Exception {
> -                try {
> -                    callback.completed(operationFuture.get());
> -                } catch (final ExecutionException ex) {
> -                    if (ex.getCause() instanceof Exception) {
> -                        callback.failed((Exception) ex.getCause());
> -                    } else {
> -                        callback.failed(ex);
> -                    }
> +        operationFuture.addListener(future -> {
> +            try {
> +                callback.completed(operationFuture.get());
> +            } catch (final ExecutionException ex) {
> +                if (ex.getCause() instanceof Exception) {
> +                    callback.failed((Exception) ex.getCause());
> +                } else {
> +                    callback.failed(ex);
>                  }
>              }
> -
>          });
>          return Operations.cancellable(operationFuture);
>      }
> @@ -187,21 +178,16 @@ public class MemcachedHttpAsyncCacheStorage extends
> AbstractBinaryAsyncCacheStor
>      @Override
>      protected Cancellable restore(final String storageKey, final
> FutureCallback<byte[]> callback) {
>          final GetFuture<Object> getFuture = client.asyncGet(storageKey);
> -        getFuture.addListener(new GetCompletionListener() {
> -
> -            @Override
> -            public void onComplete(final GetFuture<?> future) throws
> Exception {
> -                try {
> -                    callback.completed(castAsByteArray(getFuture.get()));
> -                } catch (final ExecutionException ex) {
> -                    if (ex.getCause() instanceof Exception) {
> -                        callback.failed((Exception) ex.getCause());
> -                    } else {
> -                        callback.failed(ex);
> -                    }
> +        getFuture.addListener(future -> {
> +            try {
> +                callback.completed(castAsByteArray(getFuture.get()));
> +            } catch (final ExecutionException ex) {
> +                if (ex.getCause() instanceof Exception) {
> +                    callback.failed((Exception) ex.getCause());
> +                } else {
> +                    callback.failed(ex);
>                  }
>              }
> -
>          });
>          return Operations.cancellable(getFuture);
>      }
> @@ -242,17 +228,13 @@ public class MemcachedHttpAsyncCacheStorage extends
> AbstractBinaryAsyncCacheStor
>      @Override
>      protected Cancellable bulkRestore(final Collection<String>
> storageKeys, final FutureCallback<Map<String, byte[]>> callback) {
>          final BulkFuture<Map<String, Object>> future =
> client.asyncGetBulk(storageKeys);
> -        future.addListener(new BulkGetCompletionListener() {
> -
> -            @Override
> -            public void onComplete(final BulkGetFuture<?> future) throws
> Exception {
> -                final Map<String, ?> storageObjectMap = future.get();
> -                final Map<String, byte[]> resultMap = new
> HashMap<>(storageObjectMap.size());
> -                for (final Map.Entry<String, ?> resultEntry:
> storageObjectMap.entrySet()) {
> -                    resultMap.put(resultEntry.getKey(),
> castAsByteArray(resultEntry.getValue()));
> -                }
> -                callback.completed(resultMap);
> +        future.addListener(future1 -> {
> +            final Map<String, ?> storageObjectMap = future1.get();
> +            final Map<String, byte[]> resultMap = new
> HashMap<>(storageObjectMap.size());
> +            for (final Map.Entry<String, ?> resultEntry:
> storageObjectMap.entrySet()) {
> +                resultMap.put(resultEntry.getKey(),
> castAsByteArray(resultEntry.getValue()));
>              }
> +            callback.completed(resultMap);
>          });
>          return Operations.cancellable(future);
>      }
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
> index 88b8cbc..791ae61 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
> @@ -217,7 +217,7 @@ public class TestHttpCacheEntry {
>      public void canProvideVariantMap() {
>          new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
>                  new Header[]{}, mockResource,
> -                new HashMap<String,String>());
> +                new HashMap<>());
>      }
>
>      @Test
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
> index 8d83f7f..67e75a2 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
> @@ -155,7 +155,7 @@ public abstract class AbstractProtocolTest {
>
>  EasyMock.expect(mockCache.getCacheEntry(EasyMock.isA(HttpHost.class),
> EasyMock.isA(HttpRequest.class)))
>              .andReturn(null).anyTimes();
>
>  
> EasyMock.expect(mockCache.getVariantCacheEntriesWithEtags(EasyMock.isA(HttpHost.class),
> EasyMock.isA(HttpRequest.class)))
> -            .andReturn(new HashMap<String,Variant>()).anyTimes();
> +            .andReturn(new HashMap<>()).anyTimes();
>
>          mockCache.flushCacheEntriesFor(EasyMock.isA(HttpHost.class),
> EasyMock.isA(HttpRequest.class));
>          EasyMock.expectLastCall().anyTimes();
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
> index f0b1ad6..1692054 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
> @@ -35,7 +35,6 @@ import java.util.HashMap;
>  import java.util.Map;
>  import java.util.concurrent.atomic.AtomicInteger;
>
> -import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
>  import org.apache.hc.client5.http.cache.HttpCacheEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheUpdateException;
> @@ -52,7 +51,6 @@ import org.mockito.ArgumentCaptor;
>  import org.mockito.ArgumentMatchers;
>  import org.mockito.Mock;
>  import org.mockito.Mockito;
> -import org.mockito.invocation.InvocationOnMock;
>  import org.mockito.junit.MockitoJUnitRunner;
>  import org.mockito.stubbing.Answer;
>
> @@ -90,16 +88,11 @@ public class TestAbstractSerializingAsyncCacheStorage {
>          Mockito.when(impl.store(
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> -                callback.completed(true);
> -                return cancellable;
> -            }
> -
> -        });
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> +                    callback.completed(true);
> +                    return cancellable;
> +                });
>
>          impl.putEntry(key, value, operationCallback);
>
> @@ -114,15 +107,10 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          final String key = "foo";
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
> -        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> -                callback.completed(null);
> -                return cancellable;
> -            }
> -
> +        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +            final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> +            callback.completed(null);
> +            return cancellable;
>          });
>
>          impl.getEntry(key, cacheEntryCallback);
> @@ -138,15 +126,10 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
> -        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> -                callback.completed(serialize(key, value));
> -                return cancellable;
> -            }
> -
> +        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +            final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> +            callback.completed(serialize(key, value));
> +            return cancellable;
>          });
>
>          impl.getEntry(key, cacheEntryCallback);
> @@ -162,15 +145,10 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          final String key = "foo";
>          final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
> -        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> -                callback.completed(serialize("not-foo", value));
> -                return cancellable;
> -            }
> -
> +        Mockito.when(impl.restore(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<byte[]>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +            final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> +            callback.completed(serialize("not-foo", value));
> +            return cancellable;
>          });
>
>          impl.getEntry(key, cacheEntryCallback);
> @@ -187,16 +165,11 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
>          Mockito.when(impl.delete(
>                  ArgumentMatchers.eq("bar"),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(1);
> -                callback.completed(true);
> -                return cancellable;
> -            }
> -
> -        });
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(1);
> +                    callback.completed(true);
> +                    return cancellable;
> +                });
>          impl.removeEntry(key, operationCallback);
>
>          Mockito.verify(impl).delete("bar", operationCallback);
> @@ -209,38 +182,23 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          final HttpCacheEntry updatedValue =
> HttpTestUtils.makeCacheEntry();
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
> -        Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> -                callback.completed(null);
> -                return cancellable;
> -            }
> -
> +        Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +            final FutureCallback<byte[]> callback =
> invocation.getArgument(1);
> +            callback.completed(null);
> +            return cancellable;
>          });
>          Mockito.when(impl.store(
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> -                callback.completed(true);
> -                return cancellable;
> -            }
> -
> -        });
> -
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                Assert.assertThat(existing, CoreMatchers.nullValue());
> -                return updatedValue;
> -            }
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> +                    callback.completed(true);
> +                    return cancellable;
> +                });
>
> +        impl.updateEntry(key, existing -> {
> +            Assert.assertThat(existing, CoreMatchers.nullValue());
> +            return updatedValue;
>          }, operationCallback);
>
>          Mockito.verify(impl).getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any());
> @@ -255,40 +213,23 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>          final HttpCacheEntry updatedValue =
> HttpTestUtils.makeCacheEntry();
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
> -        Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<String> callback =
> invocation.getArgument(1);
> -                callback.completed("stuff");
> -                return cancellable;
> -            }
> -
> +        Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +            final FutureCallback<String> callback =
> invocation.getArgument(1);
> +            callback.completed("stuff");
> +            return cancellable;
>          });
>
>  Mockito.when(impl.getStorageObject("stuff")).thenReturn(serialize(key,
> existingValue));
>          Mockito.when(impl.updateCAS(
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.eq("stuff"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> -                callback.completed(true);
> -                return cancellable;
> -            }
> -
> -        });
> -
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> +                    callback.completed(true);
> +                    return cancellable;
> +                });
>
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                return updatedValue;
> -            }
> -
> -        }, operationCallback);
> +        impl.updateEntry(key, existing -> updatedValue,
> operationCallback);
>
>          Mockito.verify(impl).getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any());
>          Mockito.verify(impl).getStorageObject("stuff");
> @@ -304,39 +245,24 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
>          Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer(
> -                new Answer<Cancellable>() {
> -
> -                    @Override
> -                    public Cancellable answer(final InvocationOnMock
> invocation) throws Throwable {
> -                        final FutureCallback<String> callback =
> invocation.getArgument(1);
> -                        callback.completed("stuff");
> -                        return cancellable;
> -                    }
> -
> +                (Answer<Cancellable>) invocation -> {
> +                    final FutureCallback<String> callback =
> invocation.getArgument(1);
> +                    callback.completed("stuff");
> +                    return cancellable;
>                  });
>
>  Mockito.when(impl.getStorageObject("stuff")).thenReturn(serialize("not-foo",
> existingValue));
>          Mockito.when(impl.store(
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> -                callback.completed(true);
> -                return cancellable;
> -            }
> -
> -        });
> -
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                Assert.assertThat(existing, CoreMatchers.nullValue());
> -                return updatedValue;
> -            }
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(2);
> +                    callback.completed(true);
> +                    return cancellable;
> +                });
>
> +        impl.updateEntry(key, existing -> {
> +            Assert.assertThat(existing, CoreMatchers.nullValue());
> +            return updatedValue;
>          }, operationCallback);
>
>          Mockito.verify(impl).getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any());
> @@ -355,15 +281,10 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
>          Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer(
> -                new Answer<Cancellable>() {
> -
> -                    @Override
> -                    public Cancellable answer(final InvocationOnMock
> invocation) throws Throwable {
> -                        final FutureCallback<String> callback =
> invocation.getArgument(1);
> -                        callback.completed("stuff");
> -                        return cancellable;
> -                    }
> -
> +                (Answer<Cancellable>) invocation -> {
> +                    final FutureCallback<String> callback =
> invocation.getArgument(1);
> +                    callback.completed("stuff");
> +                    return cancellable;
>                  });
>
>  Mockito.when(impl.getStorageObject("stuff")).thenReturn(serialize(key,
> existingValue));
>          final AtomicInteger count = new AtomicInteger(0);
> @@ -371,29 +292,17 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.eq("stuff"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> -                if (count.incrementAndGet() == 1) {
> -                    callback.completed(false);
> -                } else {
> -                    callback.completed(true);
> -                }
> -                return cancellable;
> -            }
> -
> -        });
> -
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                return updatedValue;
> -            }
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> +                    if (count.incrementAndGet() == 1) {
> +                        callback.completed(false);
> +                    } else {
> +                        callback.completed(true);
> +                    }
> +                    return cancellable;
> +                });
>
> -        }, operationCallback);
> +        impl.updateEntry(key, existing -> updatedValue,
> operationCallback);
>
>          Mockito.verify(impl,
> Mockito.times(2)).getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any());
>          Mockito.verify(impl, Mockito.times(2)).getStorageObject("stuff");
> @@ -410,15 +319,10 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>
>          Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
>          Mockito.when(impl.getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any())).thenAnswer(
> -                new Answer<Cancellable>() {
> -
> -                    @Override
> -                    public Cancellable answer(final InvocationOnMock
> invocation) throws Throwable {
> -                        final FutureCallback<String> callback =
> invocation.getArgument(1);
> -                        callback.completed("stuff");
> -                        return cancellable;
> -                    }
> -
> +                (Answer<Cancellable>) invocation -> {
> +                    final FutureCallback<String> callback =
> invocation.getArgument(1);
> +                    callback.completed("stuff");
> +                    return cancellable;
>                  });
>
>  Mockito.when(impl.getStorageObject("stuff")).thenReturn(serialize(key,
> existingValue));
>          final AtomicInteger count = new AtomicInteger(0);
> @@ -426,29 +330,17 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>                  ArgumentMatchers.eq("bar"),
>                  ArgumentMatchers.eq("stuff"),
>                  ArgumentMatchers.<byte[]>any(),
> -
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer(new
> Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> -                if (count.incrementAndGet() <= 3) {
> -                    callback.completed(false);
> -                } else {
> -                    callback.completed(true);
> -                }
> -                return cancellable;
> -            }
> -
> -        });
> -
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                return updatedValue;
> -            }
> +
> ArgumentMatchers.<FutureCallback<Boolean>>any())).thenAnswer((Answer<Cancellable>)
> invocation -> {
> +                    final FutureCallback<Boolean> callback =
> invocation.getArgument(3);
> +                    if (count.incrementAndGet() <= 3) {
> +                        callback.completed(false);
> +                    } else {
> +                        callback.completed(true);
> +                    }
> +                    return cancellable;
> +                });
>
> -        }, operationCallback);
> +        impl.updateEntry(key, existing -> updatedValue,
> operationCallback);
>
>          Mockito.verify(impl,
> Mockito.times(3)).getForUpdateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.<FutureCallback<String>>any());
>          Mockito.verify(impl, Mockito.times(3)).getStorageObject("stuff");
> @@ -472,23 +364,19 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>
>          when(impl.bulkRestore(
>                  ArgumentMatchers.<String>anyCollection(),
> -                ArgumentMatchers.<FutureCallback<Map<String,
> byte[]>>>any())).thenAnswer(new Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final Collection<String> keys = invocation.getArgument(0);
> -                final FutureCallback<Map<String, byte[]>> callback =
> invocation.getArgument(1);
> -                final Map<String, byte[]> resultMap = new HashMap<>();
> -                if (keys.contains(storageKey1)) {
> -                    resultMap.put(storageKey1, serialize(key1, value1));
> -                }
> -                if (keys.contains(storageKey2)) {
> -                    resultMap.put(storageKey2, serialize(key2, value2));
> -                }
> -                callback.completed(resultMap);
> -                return cancellable;
> -            }
> -        });
> +                ArgumentMatchers.<FutureCallback<Map<String,
> byte[]>>>any())).thenAnswer((Answer<Cancellable>) invocation -> {
> +                    final Collection<String> keys =
> invocation.getArgument(0);
> +                    final FutureCallback<Map<String, byte[]>> callback =
> invocation.getArgument(1);
> +                    final Map<String, byte[]> resultMap = new HashMap<>();
> +                    if (keys.contains(storageKey1)) {
> +                        resultMap.put(storageKey1, serialize(key1,
> value1));
> +                    }
> +                    if (keys.contains(storageKey2)) {
> +                        resultMap.put(storageKey2, serialize(key2,
> value2));
> +                    }
> +                    callback.completed(resultMap);
> +                    return cancellable;
> +                });
>
>          impl.getEntries(Arrays.asList(key1, key2),
> bulkCacheEntryCallback);
>          final ArgumentCaptor<Map<String, HttpCacheEntry>> argumentCaptor
> = ArgumentCaptor.forClass(Map.class);
> @@ -521,23 +409,19 @@ public class
> TestAbstractSerializingAsyncCacheStorage {
>
>          when(impl.bulkRestore(
>                  ArgumentMatchers.<String>anyCollection(),
> -                ArgumentMatchers.<FutureCallback<Map<String,
> byte[]>>>any())).thenAnswer(new Answer<Cancellable>() {
> -
> -            @Override
> -            public Cancellable answer(final InvocationOnMock invocation)
> throws Throwable {
> -                final Collection<String> keys = invocation.getArgument(0);
> -                final FutureCallback<Map<String, byte[]>> callback =
> invocation.getArgument(1);
> -                final Map<String, byte[]> resultMap = new HashMap<>();
> -                if (keys.contains(storageKey1)) {
> -                    resultMap.put(storageKey1, serialize(key1, value1));
> -                }
> -                if (keys.contains(storageKey2)) {
> -                    resultMap.put(storageKey2, serialize("not foo",
> value2));
> -                }
> -                callback.completed(resultMap);
> -                return cancellable;
> -            }
> -        });
> +                ArgumentMatchers.<FutureCallback<Map<String,
> byte[]>>>any())).thenAnswer((Answer<Cancellable>) invocation -> {
> +                    final Collection<String> keys =
> invocation.getArgument(0);
> +                    final FutureCallback<Map<String, byte[]>> callback =
> invocation.getArgument(1);
> +                    final Map<String, byte[]> resultMap = new HashMap<>();
> +                    if (keys.contains(storageKey1)) {
> +                        resultMap.put(storageKey1, serialize(key1,
> value1));
> +                    }
> +                    if (keys.contains(storageKey2)) {
> +                        resultMap.put(storageKey2, serialize("not foo",
> value2));
> +                    }
> +                    callback.completed(resultMap);
> +                    return cancellable;
> +                });
>
>          impl.getEntries(Arrays.asList(key1, key2),
> bulkCacheEntryCallback);
>          final ArgumentCaptor<Map<String, HttpCacheEntry>> argumentCaptor
> = ArgumentCaptor.forClass(Map.class);
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
> index 5fd0b03..1cbbaae 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
> @@ -35,7 +35,6 @@ import java.util.Collection;
>  import java.util.HashMap;
>  import java.util.Map;
>
> -import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
>  import org.apache.hc.client5.http.cache.HttpCacheEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
>  import org.apache.hc.client5.http.cache.HttpCacheUpdateException;
> @@ -48,7 +47,6 @@ import org.mockito.Answers;
>  import org.mockito.ArgumentCaptor;
>  import org.mockito.ArgumentMatchers;
>  import org.mockito.Mockito;
> -import org.mockito.invocation.InvocationOnMock;
>  import org.mockito.stubbing.Answer;
>
>  @SuppressWarnings("boxing") // test code
> @@ -143,14 +141,9 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.digestToStorageKey(key)).thenReturn("bar");
>          when(impl.getForUpdateCAS("bar")).thenReturn(null);
>
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                Assert.assertThat(existing, CoreMatchers.nullValue());
> -                return updatedValue;
> -            }
> -
> +        impl.updateEntry(key, existing -> {
> +            Assert.assertThat(existing, CoreMatchers.nullValue());
> +            return updatedValue;
>          });
>
>          verify(impl).getForUpdateCAS("bar");
> @@ -168,14 +161,7 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.getStorageObject("stuff")).thenReturn(serialize(key,
> existingValue));
>          when(impl.updateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.eq("stuff"),
> ArgumentMatchers.<byte[]>any())).thenReturn(true);
>
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                return updatedValue;
> -            }
> -
> -        });
> +        impl.updateEntry(key, existing -> updatedValue);
>
>          verify(impl).getForUpdateCAS("bar");
>          verify(impl).getStorageObject("stuff");
> @@ -193,14 +179,9 @@ public class TestAbstractSerializingCacheStorage {
>
>  when(impl.getStorageObject("stuff")).thenReturn(serialize("not-foo",
> existingValue));
>          when(impl.updateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.eq("stuff"),
> ArgumentMatchers.<byte[]>any())).thenReturn(true);
>
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                Assert.assertThat(existing, CoreMatchers.nullValue());
> -                return updatedValue;
> -            }
> -
> +        impl.updateEntry(key, existing -> {
> +            Assert.assertThat(existing, CoreMatchers.nullValue());
> +            return updatedValue;
>          });
>
>          verify(impl).getForUpdateCAS("bar");
> @@ -219,14 +200,7 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.getStorageObject("stuff")).thenReturn(serialize(key,
> existingValue));
>          when(impl.updateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.eq("stuff"),
> ArgumentMatchers.<byte[]>any())).thenReturn(false, true);
>
> -        impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -            @Override
> -            public HttpCacheEntry execute(final HttpCacheEntry existing)
> throws ResourceIOException {
> -                return updatedValue;
> -            }
> -
> -        });
> +        impl.updateEntry(key, existing -> updatedValue);
>
>          verify(impl, Mockito.times(2)).getForUpdateCAS("bar");
>          verify(impl, Mockito.times(2)).getStorageObject("stuff");
> @@ -245,14 +219,7 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.updateCAS(ArgumentMatchers.eq("bar"),
> ArgumentMatchers.eq("stuff"),
> ArgumentMatchers.<byte[]>any())).thenReturn(false, false, false, true);
>
>          try {
> -            impl.updateEntry(key, new HttpCacheCASOperation() {
> -
> -                @Override
> -                public HttpCacheEntry execute(final HttpCacheEntry
> existing) throws ResourceIOException {
> -                    return updatedValue;
> -                }
> -
> -            });
> +            impl.updateEntry(key, existing -> updatedValue);
>              Assert.fail("HttpCacheUpdateException expected");
>          } catch (final HttpCacheUpdateException ignore) {
>          }
> @@ -274,20 +241,16 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.digestToStorageKey(key1)).thenReturn(storageKey1);
>          when(impl.digestToStorageKey(key2)).thenReturn(storageKey2);
>
> -
> when(impl.bulkRestore(ArgumentMatchers.<String>anyCollection())).thenAnswer(new
> Answer<Map<String, byte[]>>() {
> -
> -            @Override
> -            public Map<String, byte[]> answer(final InvocationOnMock
> invocation) throws Throwable {
> -                final Collection<String> keys = invocation.getArgument(0);
> -                final Map<String, byte[]> resultMap = new HashMap<>();
> -                if (keys.contains(storageKey1)) {
> -                    resultMap.put(storageKey1, serialize(key1, value1));
> -                }
> -                if (keys.contains(storageKey2)) {
> -                    resultMap.put(storageKey2, serialize(key2, value2));
> -                }
> -                return resultMap;
> +
> when(impl.bulkRestore(ArgumentMatchers.<String>anyCollection())).thenAnswer((Answer<Map<String,
> byte[]>>) invocation -> {
> +            final Collection<String> keys = invocation.getArgument(0);
> +            final Map<String, byte[]> resultMap = new HashMap<>();
> +            if (keys.contains(storageKey1)) {
> +                resultMap.put(storageKey1, serialize(key1, value1));
>              }
> +            if (keys.contains(storageKey2)) {
> +                resultMap.put(storageKey2, serialize(key2, value2));
> +            }
> +            return resultMap;
>          });
>
>          final Map<String, HttpCacheEntry> entryMap =
> impl.getEntries(Arrays.asList(key1, key2));
> @@ -312,20 +275,16 @@ public class TestAbstractSerializingCacheStorage {
>          when(impl.digestToStorageKey(key1)).thenReturn(storageKey1);
>          when(impl.digestToStorageKey(key2)).thenReturn(storageKey2);
>
> -
> when(impl.bulkRestore(ArgumentMatchers.<String>anyCollection())).thenAnswer(new
> Answer<Map<String, byte[]>>() {
> -
> -            @Override
> -            public Map<String, byte[]> answer(final InvocationOnMock
> invocation) throws Throwable {
> -                final Collection<String> keys = invocation.getArgument(0);
> -                final Map<String, byte[]> resultMap = new HashMap<>();
> -                if (keys.contains(storageKey1)) {
> -                    resultMap.put(storageKey1, serialize(key1, value1));
> -                }
> -                if (keys.contains(storageKey2)) {
> -                    resultMap.put(storageKey2, serialize("not foo",
> value2));
> -                }
> -                return resultMap;
> +
> when(impl.bulkRestore(ArgumentMatchers.<String>anyCollection())).thenAnswer((Answer<Map<String,
> byte[]>>) invocation -> {
> +            final Collection<String> keys = invocation.getArgument(0);
> +            final Map<String, byte[]> resultMap = new HashMap<>();
> +            if (keys.contains(storageKey1)) {
> +                resultMap.put(storageKey1, serialize(key1, value1));
> +            }
> +            if (keys.contains(storageKey2)) {
> +                resultMap.put(storageKey2, serialize("not foo", value2));
>              }
> +            return resultMap;
>          });
>
>          final Map<String, HttpCacheEntry> entryMap =
> impl.getEntries(Arrays.asList(key1, key2));
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedHttpResponseGenerator.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedHttpResponseGenerator.java
> index ace354b..66aa443 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedHttpResponseGenerator.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedHttpResponseGenerator.java
> @@ -55,7 +55,7 @@ public class TestCachedHttpResponseGenerator {
>
>      @Before
>      public void setUp() {
> -        entry = HttpTestUtils.makeCacheEntry(new HashMap<String,
> String>());
> +        entry = HttpTestUtils.makeCacheEntry(new HashMap<>());
>          request = HttpTestUtils.makeDefaultRequest();
>          mockValidityPolicy = mock(CacheValidityPolicy.class);
>          impl = new CachedHttpResponseGenerator(mockValidityPolicy);
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
> index 171da3e..8ec3db6 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
> @@ -170,7 +170,7 @@ public class TestCachingExec extends
> TestCachingExecChain {
>          mockImplMethods(CALL_BACKEND);
>          requestPolicyAllowsCaching(true);
>          getCacheEntryReturns(null);
> -        getVariantCacheEntriesReturns(new HashMap<String,Variant>());
> +        getVariantCacheEntriesReturns(new HashMap<>());
>
>          requestIsFatallyNonCompliant(null);
>
> diff --git
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
> index 186b886..58ca6a0 100644
> ---
> a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
> +++
> b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
> @@ -34,7 +34,6 @@ import java.util.Map;
>  import org.apache.hc.client5.http.cache.HeaderConstants;
>  import org.apache.hc.client5.http.cache.HttpCacheEntry;
>  import org.apache.hc.client5.http.utils.DateUtils;
> -import org.apache.hc.core5.function.Factory;
>  import org.apache.hc.core5.http.Header;
>  import org

Reply via email to