use of retrofit2.http.QueryMap in project retrofit by square.
the class RequestBuilderTest method fieldParamMapsConvertedToNullShouldError.
@Test
public void fieldParamMapsConvertedToNullShouldError() throws Exception {
class Example {
@FormUrlEncoded
@POST("/query")
Call<ResponseBody> queryPath(@FieldMap 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("Field map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
}
}
use of retrofit2.http.QueryMap in project retrofit by square.
the class RequestBuilderTest method queryMapSupportsSubclasses.
@Test
public void queryMapSupportsSubclasses() {
class Foo extends HashMap<String, String> {
}
class Example {
//
@GET("/")
Call<ResponseBody> method(@QueryMap Foo a) {
return null;
}
}
Foo foo = new Foo();
foo.put("hello", "world");
Request request = buildRequest(Example.class, foo);
assertThat(request.url().toString()).isEqualTo("http://example.com/?hello=world");
}
use of retrofit2.http.QueryMap in project retrofit by square.
the class RequestBuilderTest method getWithEncodedQueryParamMap.
@Test
public void getWithEncodedQueryParamMap() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryMap(encoded = true) Map<String, Object> query) {
return null;
}
}
Map<String, Object> params = new LinkedHashMap<>();
params.put("kit", "k%20t");
params.put("pi%20ng", "p%20g");
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=k%20t&pi%20ng=p%20g");
assertThat(request.body()).isNull();
}
use of retrofit2.http.QueryMap 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.QueryMap 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