@Test
public void shouldReturnErrorStreamForFailingInputStream() throws Throwable {

  final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
  when(mockHttpURLConnection.getContentLength()).thenReturn(-1);
  //noinspection unchecked
  when(mockHttpURLConnection.getInputStream()).thenThrow(IOException.class);
  when(mockHttpURLConnection.getErrorStream()).thenReturn(inputStream);
  assertThat(httpFunction().apply(HTTP_GET_REQUEST).get().getBody(), is(RESPONSE_BODY));
  verify(mockHttpURLConnection).disconnect();
}