### Question:
FailedHttpResponseException extends RuntimeException { public String getEntityAsString() { try { return EntityUtils.toString(entity, "UTF-8"); } catch (IOException ex) { throw new RuntimeException(ex); } } FailedHttpResponseException(int statusCode, HttpEntity entity); int getStatusCode(); HttpEntity getEntity(); String getEntityAsString();  }### Answer:
@Test public void entityAsStringReturnsCorrectly() throws IllegalStateException, IOException { InputStream content = new ByteArrayInputStream("testContent".getBytes("UTF-8")); when(entity.getContent()).thenReturn(content); assertEquals("testContent", exception.getEntityAsString()); }
@Test(expected = RuntimeException.class) public void entityAsStringThrowsRuntimeExceptionOnIOException() throws IllegalStateException, IOException { when(entity.getContent()).thenThrow(new IOException()); exception.getEntityAsString(); }