return error stream, if input stream could not be returned

This commit is contained in:
Sebastian Sdorra
2015-05-01 14:21:15 +02:00
parent 3c6306059f
commit 722d2616a8
2 changed files with 54 additions and 4 deletions

View File

@@ -92,6 +92,28 @@ public class DefaultAdvancedHttpResponseTest
assertEquals("test", content.asCharSource(Charsets.UTF_8).read());
}
/**
* Method description
*
*
* @throws IOException
*/
@Test
public void testContentAsByteSourceWithFailedRequest() throws IOException
{
ByteArrayInputStream bais =
new ByteArrayInputStream("test".getBytes(Charsets.UTF_8));
when(connection.getInputStream()).thenThrow(IOException.class);
when(connection.getErrorStream()).thenReturn(bais);
AdvancedHttpResponse response = new DefaultAdvancedHttpResponse(connection,
404, "NOT FOUND");
ByteSource content = response.contentAsByteSource();
assertEquals("test", content.asCharSource(Charsets.UTF_8).read());
}
/**
* Method description
*