use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method formEncodedFieldOptional.
@Test
public void formEncodedFieldOptional() {
class Example {
//
@FormUrlEncoded
//
@POST("/foo")
Call<ResponseBody> method(@Field("foo") String foo, @Field("ping") String ping, @Field("kit") String kit) {
return null;
}
}
Request request = buildRequest(Example.class, "bar", null, "kat");
assertBody(request.body(), "foo=bar&kit=kat");
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method bodyWithPathParams.
@Test
public void bodyWithPathParams() {
class Example {
//
@POST("/foo/bar/{ping}/{kit}/")
Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body, @Path("kit") String kit) {
return null;
}
}
RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
Request request = buildRequest(Example.class, "pong", body, "kat");
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/kat/");
assertBody(request.body(), "Hi!");
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method headerParamToString.
@Test
public void headerParamToString() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Header("kit") BigInteger kit) {
return null;
}
}
Request request = buildRequest(Example.class, new BigInteger("1234"));
assertThat(request.method()).isEqualTo("GET");
okhttp3.Headers headers = request.headers();
assertThat(headers.size()).isEqualTo(1);
assertThat(headers.get("kit")).isEqualTo("1234");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of okhttp3.ResponseBody in project retrofit by square.
the class ResponseTest method errorWithSuccessRawResponseThrows.
@Test
public void errorWithSuccessRawResponseThrows() {
ResponseBody errorBody = ResponseBody.create(null, "Broken!");
try {
Response.error(errorBody, successResponse);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("rawResponse should not be successful response");
}
}
use of okhttp3.ResponseBody in project retrofit by square.
the class ResponseTest method errorWithSuccessCodeThrows.
@Test
public void errorWithSuccessCodeThrows() {
ResponseBody errorBody = ResponseBody.create(null, "Broken!");
try {
Response.error(200, errorBody);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("code < 400: 200");
}
}
Aggregations