use of okhttp3.ResponseBody in project retrofit by square.
the class WireConverterFactoryTest method deserializeWrongClass.
@Test
public void deserializeWrongClass() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
try {
service.wrongClass();
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("" + "Unable to create converter for class java.lang.String\n" + " for method Service.wrongClass");
assertThat(e.getCause()).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + " Tried:\n" + " * retrofit2.BuiltInConverters\n" + " * retrofit2.converter.wire.WireConverterFactory");
}
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method getWithEncodedPathStillPreventsRequestSplitting.
@Test
public void getWithEncodedPathStillPreventsRequestSplitting() {
class Example {
//
@GET("/foo/bar/{ping}/")
Call<ResponseBody> method(@Path(value = "ping", encoded = true) String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "baz/\r\npong");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/baz/pong/");
assertThat(request.body()).isNull();
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method formEncodedWithEncodedNameFieldParamMap.
@Test
public void formEncodedWithEncodedNameFieldParamMap() {
class Example {
//
@FormUrlEncoded
//
@POST("/foo")
Call<ResponseBody> method(@FieldMap(encoded = true) Map<String, Object> fieldMap) {
return null;
}
}
Map<String, Object> fieldMap = new LinkedHashMap<>();
fieldMap.put("k%20it", "k%20at");
fieldMap.put("pin%20g", "po%20ng");
Request request = buildRequest(Example.class, fieldMap);
assertBody(request.body(), "k%20it=k%20at&pin%20g=po%20ng");
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method normalPostWithPathParam.
@Test
public void normalPostWithPathParam() {
class Example {
//
@POST("/foo/bar/{ping}/")
Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
Request request = buildRequest(Example.class, "pong", body);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/");
assertBody(request.body(), "Hi!");
}
use of okhttp3.ResponseBody in project retrofit by square.
the class RequestBuilderTest method customMethodNoBody.
@Test
public void customMethodNoBody() {
class Example {
@HTTP(method = "CUSTOM1", path = "/foo")
Call<ResponseBody> method() {
return null;
}
}
Request request = buildRequest(Example.class);
assertThat(request.method()).isEqualTo("CUSTOM1");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo");
assertThat(request.body()).isNull();
}
Aggregations