use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithQueryParamMap.
@Test
public void getWithQueryParamMap() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryMap Map<String, Object> query) {
return null;
}
}
Map<String, Object> params = new LinkedHashMap<>();
params.put("kit", "kat");
params.put("ping", "pong");
Request request = buildRequest(Example.class, params);
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?kit=kat&ping=pong");
assertThat(request.body()).isNull();
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method fieldParamsSkippedIfConvertedToNull.
@Test
public void fieldParamsSkippedIfConvertedToNull() throws Exception {
class Example {
@FormUrlEncoded
@POST("/query")
Call<ResponseBody> queryPath(@Field("a") Object a) {
return null;
}
}
Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
Request request = buildRequest(Example.class, retrofitBuilder, "Ignored");
assertThat(request.url().toString()).doesNotContain("Ignored");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method customMethodWithBody.
@Test
public void customMethodWithBody() {
class Example {
@HTTP(method = "CUSTOM2", path = "/foo", hasBody = true)
Call<ResponseBody> method(@Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
Request request = buildRequest(Example.class, body);
assertThat(request.method()).isEqualTo("CUSTOM2");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo");
assertBody(request.body(), "hi");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithQueryNameParamPrimitiveArray.
@Test
public void getWithQueryNameParamPrimitiveArray() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName int[] keys) {
return null;
}
}
int[] values = { 1, 2, 3, 1 };
Request request = buildRequest(Example.class, new Object[] { values });
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?1&2&3&1");
assertThat(request.body()).isNull();
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithPathAndQueryParam.
@Test
public void getWithPathAndQueryParam() {
class Example {
//
@GET("/foo/bar/{ping}/")
Call<ResponseBody> method(@Path("ping") String ping, @Query("kit") String kit, @Query("riff") String riff) {
return null;
}
}
Request request = buildRequest(Example.class, "pong", "kat", "raff");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/?kit=kat&riff=raff");
assertThat(request.body()).isNull();
}
Aggregations