Source:
void newCallShouldProduceExpectedResult() { val request = new Request.Builder().url("<LINK_0>").build(); val httpClient = mock(AsyncHttpClient.class); Consumer<Request> onRequestStart = createConsumer(); Consumer<Throwable> onRequestFailure = createConsumer(); Consumer<Response> onRequestSuccess = createConsumer(); Consumer<RequestBuilder> requestCustomizer = createConsumer(); val factory = AsyncHttpClientCallFactory.builder() .httpClient(httpClient) .onRequestStart(onRequestStart) .onRequestFailure(onRequestFailure) .onRequestSuccess(onRequestSuccess) .requestCustomizer(requestCustomizer) .build(); Assert.assertTrue(factory.getHttpClient() == httpClient); Assert.assertTrue(factory.getOnRequestStart() == onRequestStart); Assert.assertTrue(factory.getOnRequestFailure() == onRequestFailure); Assert.assertTrue(factory.getOnRequestSuccess() == onRequestSuccess); Assert.assertTrue(factory.getRequestCustomizer() == requestCustomizer); val call = (AsyncHttpClientCall) factory.newCall(request); Assert.assertNotNull(call); Assert.assertTrue(call.request() == request); Assert.assertTrue(call.getHttpClient() == httpClient); Assert.assertTrue(call.getOnRequestStart() == onRequestStart); Assert.assertTrue(call.getOnRequestFailure() == onRequestFailure); Assert.assertTrue(call.getOnRequestSuccess() == onRequestSuccess); Assert.assertTrue(call.getRequestCustomizer() == requestCustomizer); }

Target:
void newCallShouldProduceExpectedResult() { val request = new Request.Builder().url("<LINK_0>").build(); val httpClient = mock(AsyncHttpClient.class); Consumer<Request> onRequestStart = createConsumer(new AtomicInteger()); Consumer<Throwable> onRequestFailure = createConsumer(new AtomicInteger()); Consumer<Response> onRequestSuccess = createConsumer(new AtomicInteger()); Consumer<RequestBuilder> requestCustomizer = createConsumer(new AtomicInteger()); val customizer1Called = new AtomicInteger(); Consumer<AsyncHttpClientCall.AsyncHttpClientCallBuilder> callBuilderConsumer1 = builder -> { builder.onRequestStart(onRequestStart) .onRequestFailure(onRequestFailure) .onRequestSuccess(onRequestSuccess); customizer1Called.incrementAndGet(); }; val customizer2Called = new AtomicInteger(); Consumer<AsyncHttpClientCall.AsyncHttpClientCallBuilder> callBuilderConsumer2 = builder -> { builder.requestCustomizer(requestCustomizer); customizer2Called.incrementAndGet(); }; val factory = AsyncHttpClientCallFactory.builder() .httpClient(httpClient) .callCustomizer(callBuilderConsumer1) .callCustomizer(callBuilderConsumer2) .build(); assertTrue(factory.getHttpClient() == httpClient); assertTrue(factory.getCallCustomizers().size() == 2); assertTrue(customizer1Called.get() == 0); assertTrue(customizer2Called.get() == 0); val call = (AsyncHttpClientCall) factory.newCall(request); assertNotNull(call); assertTrue(customizer1Called.get() == 1); assertTrue(customizer2Called.get() == 1); assertTrue(call.request() == request); assertTrue(call.getHttpClient() == httpClient); assertEquals(call.getOnRequestStart().get(0), onRequestStart); assertEquals(call.getOnRequestFailure().get(0), onRequestFailure); assertEquals(call.getOnRequestSuccess().get(0), onRequestSuccess); assertEquals(call.getRequestCustomizers().get(0), requestCustomizer); }