use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithHttpUrl.
@Test
public void getWithHttpUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url HttpUrl url) {
return null;
}
}
Request request = buildRequest(Example.class, HttpUrl.parse("http://example.com/foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url()).isEqualTo(HttpUrl.parse("http://example.com/foo/bar/"));
assertThat(request.body()).isNull();
}
use of retrofit2.http 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");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method postWithUrl.
@Test
public void postWithUrl() {
class Example {
@POST
Call<ResponseBody> method(@Url String url, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
Request request = buildRequest(Example.class, "http://example.com/foo/bar", body);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar");
assertBody(request.body(), "hi");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithJavaUriUrl.
@Test
public void getWithJavaUriUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url URI url) {
return null;
}
}
Request request = buildRequest(Example.class, URI.create("foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http in project retrofit by square.
the class FallbackParserFinderTest method converterFactoryFallsBackToParserField.
@Test
public void converterFactoryFallsBackToParserField() {
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://localhost/").build();
ProtoConverterFactory factory = ProtoConverterFactory.create();
Converter<ResponseBody, ?> converter = factory.responseBodyConverter(FakePhone.class, new Annotation[0], retrofit);
assertThat(converter).isNotNull();
}
Aggregations