use of retrofit2.http.GET in project retrofit by square.
the class RequestBuilderTest method getWithQueryNameParamArray.
@Test
public void getWithQueryNameParamArray() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName Object[] keys) {
return null;
}
}
Object[] values = { 1, 2, null, "three", "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&three&1");
assertThat(request.body()).isNull();
}
use of retrofit2.http.GET in project retrofit by square.
the class RequestBuilderTest method getWithPathParam.
@Test
public void getWithPathParam() {
class Example {
//
@GET("/foo/bar/{ping}/")
Call<ResponseBody> method(@Path("ping") String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "po ng");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/po%20ng/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.GET in project retrofit by square.
the class RequestBuilderTest method getWithPathAndQueryHashParam.
@Test
public void getWithPathAndQueryHashParam() {
class Example {
//
@GET("/foo/bar/{ping}/")
Call<ResponseBody> method(@Path("ping") String ping, @Query("kit") String kit) {
return null;
}
}
Request request = buildRequest(Example.class, "pong#", "kat#");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong%23/?kit=kat%23");
assertThat(request.body()).isNull();
}
use of retrofit2.http.GET in project retrofit by square.
the class RequestBuilderTest method getWithQueryNameParamList.
@Test
public void getWithQueryNameParamList() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName List<Object> keys) {
return null;
}
}
List<Object> values = Arrays.<Object>asList(1, 2, null, "three", "1");
Request request = buildRequest(Example.class, values);
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?1&2&three&1");
assertThat(request.body()).isNull();
}
use of retrofit2.http.GET in project retrofit by square.
the class RequestBuilderTest method queryParamMapsConvertedToNullShouldError.
@Test
public void queryParamMapsConvertedToNullShouldError() throws Exception {
class Example {
@GET("/query")
Call<ResponseBody> queryPath(@QueryMap Map<String, String> a) {
return null;
}
}
Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
Map<String, String> queryMap = Collections.singletonMap("kit", "kat");
try {
buildRequest(Example.class, retrofitBuilder, queryMap);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageContaining("Query map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
}
}
Aggregations