コード例 #1
0
  @Test
  public void shouldSupportBasicResponseHandlerHandleResponse() throws Exception {
    Robolectric.addPendingHttpResponseWithContentType(
        200, "OK", new BasicHeader("Content-Type", "text/plain"));

    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(new HttpGet("http://www.nowhere.org"));

    assertThat(
        ((HttpUriRequest) Robolectric.getSentHttpRequest(0)).getURI(),
        equalTo(URI.create("http://www.nowhere.org")));

    Assert.assertNotNull(response);
    String responseStr = new BasicResponseHandler().handleResponse(response);
    Assert.assertEquals("OK", responseStr);
  }