### Question:
HttpClient implements LifeCycle { HttpUriRequest createClientRequest(final Request request) throws IOException { String url = new StringBuilder(128) .append(serverPool.getNext()) .append('/') .append(request.getURI()) .toString(); return (HttpUriRequest) httpRequestFactory.create(url, request); } HttpClient(
            CloseableHttpAsyncClient asyncClient,
            ServerPool serverPool,
            RequestFactory requestFactory,
            HttpAsyncResponseConsumerFactory asyncResponseConsumerFactory
    ); T execute(
            Request clientRequest,
            BlockingResponseHandler<T> responseHandler
    ); void executeAsync(
            final Request request,
            final ResponseHandler<T> responseHandler,
            final HttpClientContext httpClientContext
    ); void executeAsync(
            final Request request,
            final ResponseHandler<T> responseHandler
    ); CloseableHttpAsyncClient getAsyncClient(); @Override void start(); @Override void stop(); @Override boolean isStarted(); @Override boolean isStopped();  }### Answer:
@Test public void createClientRequestCreatesPostRequest() throws IOException { BatchRequest request = createDefaultTestBatchRequest(); HttpClient client = createDefaultTestObject(); HttpUriRequest httpRequest = client.createClientRequest(request); Assert.assertEquals("POST", httpRequest.getRequestLine().getMethod()); }
@Test public void createClientRequestCreatesRequestUsingUriProvidedByAction() throws IOException { BatchRequest request = createDefaultTestBatchRequest(); String expectedUriPart = UUID.randomUUID().toString(); when(request.getURI()).thenReturn(expectedUriPart); HttpClient client = createDefaultTestObject(); HttpUriRequest httpRequest = client.createClientRequest(request); assertTrue(httpRequest.getRequestLine().getUri().contains(expectedUriPart)); }
@Test public void createClientRequestCreatesRequestWithContentTypeHeader() throws IOException { BatchRequest request = createDefaultTestBatchRequest(); HttpClient client = createDefaultTestObject(); HttpUriRequest httpRequest = client.createClientRequest(request); HttpEntity entity = ((HttpEntityEnclosingRequest) httpRequest).getEntity(); Assert.assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue()); }
@Test public void createClientRequestDelegatesToRequestFactory() throws IOException { HCRequestFactory requestFactory = mock(HCRequestFactory.class); HttpClient client = createTestHttpClient( mock(CloseableHttpAsyncClient.class), mock(ServerPool.class), requestFactory, mock(HttpAsyncResponseConsumerFactory.class)); Request request = mock(Request.class); client.createClientRequest(request); verify(requestFactory, times(1)).create(any(), eq(request)); }