use of okhttp3.ResponseBody in project retrofit by square.
the class CallTest method responseBodyStreams.
@Test
public void responseBodyStreams() throws IOException {
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new ToStringConverterFactory()).build();
Service example = retrofit.create(Service.class);
server.enqueue(new MockResponse().setBody("1234").setSocketPolicy(DISCONNECT_DURING_RESPONSE_BODY));
Response<ResponseBody> response = example.getStreamingBody().execute();
ResponseBody streamedBody = response.body();
// When streaming we only detect socket problems as the ResponseBody is read.
try {
streamedBody.string();
fail();
} catch (IOException e) {
assertThat(e).hasMessage("unexpected end of stream");
}
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method emptyBody.
@Test
public void emptyBody() {
class Example {
//
@POST("/foo/bar/")
Call<ResponseBody> method() {
return null;
}
}
Request request = buildRequest(Example.class);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertBody(request.body(), "");
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method getWithEncodedQueryParam.
@Test
public void getWithEncodedQueryParam() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Query(value = "pi%20ng", encoded = true) String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "p%20o%20n%20g");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?pi%20ng=p%20o%20n%20g");
assertThat(request.body()).isNull();
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method delete.
@Test
public void delete() {
class Example {
//
@DELETE("/foo/bar/")
Call<ResponseBody> method() {
return null;
}
}
Request request = buildRequest(Example.class);
assertThat(request.method()).isEqualTo("DELETE");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertNull(request.body());
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method getWithUrlAbsoluteSameHost.
@Test
public void getWithUrlAbsoluteSameHost() {
class Example {
@GET
Call<ResponseBody> method(@Url String url) {
return null;
}
}
Request request = buildRequest(Example.class, "http://example.com/foo/bar/");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
Aggregations