use of retrofit2.http.GET 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.GET in project retrofit by square.
the class RequestBuilderTest method getWithStringUrlAbsolute.
@Test
public void getWithStringUrlAbsolute() {
class Example {
@GET
Call<ResponseBody> method(@Url String url) {
return null;
}
}
Request request = buildRequest(Example.class, "https://example2.com/foo/bar/");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("https://example2.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.GET 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.GET 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.GET in project retrofit by square.
the class RetrofitTest method customCallAdapter.
@Test
public void customCallAdapter() {
class GreetingCallAdapterFactory extends CallAdapter.Factory {
@Override
public CallAdapter<Object, String> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
if (getRawType(returnType) != String.class) {
return null;
}
return new CallAdapter<Object, String>() {
@Override
public Type responseType() {
return String.class;
}
@Override
public String adapt(Call<Object> call) {
return "Hi!";
}
};
}
}
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new ToStringConverterFactory()).addCallAdapterFactory(new GreetingCallAdapterFactory()).build();
StringService example = retrofit.create(StringService.class);
assertThat(example.get()).isEqualTo("Hi!");
}
Aggregations