use of retrofit2.Call in project retrofit by square.
the class RequestBuilderTest method malformedContentTypeParameterThrows.
@Test
public void malformedContentTypeParameterThrows() {
class Example {
//
@POST("/")
Call<ResponseBody> method(@Header("Content-Type") String contentType, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
try {
buildRequest(Example.class, "hello, world!", body);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Malformed content type: hello, world!");
}
}
use of retrofit2.Call 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 retrofit2.Call 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 retrofit2.Call 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 retrofit2.Call in project okhttp by square.
the class ClientAuthTest method missingClientAuthFailsForNeeds.
@Test
public void missingClientAuthFailsForNeeds() throws Exception {
OkHttpClient client = buildClient(null, clientIntermediateCa);
SSLSocketFactory socketFactory = buildServerSslSocketFactory(ClientAuth.NEEDS);
server.useHttps(socketFactory, false);
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call.execute();
fail();
} catch (SSLHandshakeException expected) {
} catch (SocketException expected) {
// JDK 9
}
}
Aggregations