use of retrofit2.http.QueryName in project retrofit by square.
the class RequestBuilderTest method getWithQueryNameParam.
@Test
public void getWithQueryNameParam() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "pong");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?pong");
assertThat(request.body()).isNull();
}
use of retrofit2.http.QueryName in project retrofit by square.
the class RequestBuilderTest method queryNameParamOptionalOmitsQuery.
@Test
public void queryNameParamOptionalOmitsQuery() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName String ping) {
return null;
}
}
Request request = buildRequest(Example.class, new Object[] { null });
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
}
use of retrofit2.http.QueryName in project retrofit by square.
the class RequestBuilderTest method getWithEncodedQueryNameParam.
@Test
public void getWithEncodedQueryNameParam() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName(encoded = true) String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "p%20o%20n%20g");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?p%20o%20n%20g");
assertThat(request.body()).isNull();
}
use of retrofit2.http.QueryName in project retrofit by square.
the class RequestBuilderTest method getWithQueryNameParamPrimitiveArray.
@Test
public void getWithQueryNameParamPrimitiveArray() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@QueryName int[] keys) {
return null;
}
}
int[] values = { 1, 2, 3, 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&3&1");
assertThat(request.body()).isNull();
}
use of retrofit2.http.QueryName 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();
}
Aggregations