@Test
public void testTransferListener() throws IOException, HttpError {

  final URI uri = URI.create("http://host/bla");
  final byte[] data = new byte[17];
  final ResponseBody body = mock(ResponseBody.class);
  when(body.contentLength()).thenReturn((long) data.length);
  when(body.source()).thenReturn(mock(BufferedSource.class));
  final InputStream inputStream = new ByteArrayInputStream(data);
  when(body.byteStream()).thenReturn(inputStream);
  final Request request = new Request.Builder().url(uri.toString()).build();
  final Response response = new Response.Builder().protocol(HTTP_1_1).body(body).request(request).code(200).build();
  final Call mockCall = mock(Call.class);
  when(mockCall.execute()).thenReturn(response);
  final OkHttpClient mockHttpClient = mock(OkHttpClient.class);
  when(mockHttpClient.newCall(any(Request.class))).thenReturn(mockCall);
  final EventLogHttpTransferListener listener = new EventLogHttpTransferListener();
  final InputStream in =
      new HttpClient(mockHttpClient).get(uri, Collections.<String, Credentials>emptyMap(), listener);
  final byte[] b = new byte[8];
  assertEquals(0, in.read());
  assertEquals(8, in.read(b));
  assertEquals(8, in.read(b, 0, 8));
  assertEquals(-1, in.read());
  in.close();
  final List<Event> events =
      ImmutableList.of(new Initialized(new Request.Builder().url(uri.toString()).build()), new Started(uri,
          data.length), new Transferred(1), new Transferred(8), new Transferred(8), Closed.INSTANCE);
  assertEquals(events, listener.getEventLog());
}