use of retrofit2.http.HeaderMap in project retrofit by square.
the class RequestBuilderTest method getWithHeaderMap.
@Test
public void getWithHeaderMap() {
class Example {
@GET("/search")
Call<ResponseBody> method(@HeaderMap Map<String, Object> headers) {
return null;
}
}
Map<String, Object> headers = new LinkedHashMap<>();
headers.put("Accept", "text/plain");
headers.put("Accept-Charset", "utf-8");
Request request = buildRequest(Example.class, headers);
assertThat(request.method()).isEqualTo("GET");
assertThat(request.url().toString()).isEqualTo("http://example.com/search");
assertThat(request.body()).isNull();
assertThat(request.headers().size()).isEqualTo(2);
assertThat(request.header("Accept")).isEqualTo("text/plain");
assertThat(request.header("Accept-Charset")).isEqualTo("utf-8");
}
use of retrofit2.http.HeaderMap in project retrofit by square.
the class RequestBuilderTest method headerMapSupportsSubclasses.
@Test
public void headerMapSupportsSubclasses() {
class Foo extends HashMap<String, String> {
}
class Example {
@GET("/search")
Call<ResponseBody> method(@HeaderMap Foo headers) {
return null;
}
}
Foo headers = new Foo();
headers.put("Accept", "text/plain");
Request request = buildRequest(Example.class, headers);
assertThat(request.url().toString()).isEqualTo("http://example.com/search");
assertThat(request.headers().size()).isEqualTo(1);
assertThat(request.header("Accept")).isEqualTo("text/plain");
}
Aggregations