@Test
public void writeEntityWithShouldOverrideHttpClientEntity() throws IOException, NoSuchFieldException, IllegalAccessException {

    OutputStream out = mock(OutputStream.class);
    HttpEntityWriter writer = mock(HttpEntityWriter.class);
    ArgumentCaptor<HttpEntity> entityCaptor = ArgumentCaptor.forClass(HttpEntity.class);
    when(writer.getContentLength()).thenReturn(123);
    toTest.writeEntityWith(writer);
    verify(request).setEntity(entityCaptor.capture());
    HttpEntity entity = entityCaptor.getValue();
    assertEquals(123, entity.getContentLength());
    assertFalse(entity.isRepeatable());
    assertTrue(entity.isStreaming());
    try {
        entity.getContent();
        fail();
    } catch (UnsupportedOperationException e) {
    }
    entity.writeTo(out);
    verify(writer).writeEntityTo(out);
}