com.xtremelabs.robolectric.tester.org.apache.http.TestHttpResponse

Here are the examples of the java api class com.xtremelabs.robolectric.tester.org.apache.http.TestHttpResponse taken from open source projects.

1. DefaultRequestDirectorTest#shouldReturnRequestsByRule_KeepsTrackOfOpenContentStreams()

Project: robolectric
File: DefaultRequestDirectorTest.java
@Test
public void shouldReturnRequestsByRule_KeepsTrackOfOpenContentStreams() throws Exception {
    TestHttpResponse testHttpResponse = new TestHttpResponse(200, "a cheery response body");
    Robolectric.addHttpResponseRule("http://some.uri", testHttpResponse);
    assertThat(testHttpResponse.entityContentStreamsHaveBeenClosed(), equalTo(true));
    HttpResponse getResponse = requestDirector.execute(null, new HttpGet("http://some.uri"), null);
    InputStream getResponseStream = getResponse.getEntity().getContent();
    assertThat(Strings.fromStream(getResponseStream), equalTo("a cheery response body"));
    assertThat(testHttpResponse.entityContentStreamsHaveBeenClosed(), equalTo(false));
    HttpResponse postResponse = requestDirector.execute(null, new HttpPost("http://some.uri"), null);
    InputStream postResponseStream = postResponse.getEntity().getContent();
    assertThat(Strings.fromStream(postResponseStream), equalTo("a cheery response body"));
    assertThat(testHttpResponse.entityContentStreamsHaveBeenClosed(), equalTo(false));
    getResponseStream.close();
    assertThat(testHttpResponse.entityContentStreamsHaveBeenClosed(), equalTo(false));
    postResponseStream.close();
    assertThat(testHttpResponse.entityContentStreamsHaveBeenClosed(), equalTo(true));
}