Skip to content

Commit

Permalink
Merge pull request square#353 from mironov-nsk/master
Browse files Browse the repository at this point in the history
Last argument should be handled for observable methods
  • Loading branch information
loganj committed Nov 10, 2013
2 parents e31c0a0 + 8a3c9fe commit 033587f
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion retrofit/src/main/java/retrofit/RequestBuilder.java
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ final class RequestBuilder implements RequestInterceptor.RequestFacade {
private final RestMethodInfo.ParamUsage[] paramUsages;
private final String requestMethod;
private final boolean isSynchronous;
private final boolean isObservable;

private final FormUrlEncodedTypedOutput formBody;
private final MultipartTypedOutput multipartBody;
@@ -50,6 +51,7 @@ final class RequestBuilder implements RequestInterceptor.RequestFacade {
paramUsages = methodInfo.requestParamUsage;
requestMethod = methodInfo.requestMethod;
isSynchronous = methodInfo.isSynchronous;
isObservable = methodInfo.isObservable;

headers = new ArrayList<Header>();
if (methodInfo.headers != null) {
@@ -163,7 +165,7 @@ void setArguments(Object[] args) {
return;
}
int count = args.length;
if (!isSynchronous) {
if (!isSynchronous && !isObservable) {
count -= 1;
}
for (int i = 0; i < count; i++) {
19 changes: 19 additions & 0 deletions retrofit/src/test/java/retrofit/RestAdapterTest.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import java.util.concurrent.Executor;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import retrofit.client.Client;
@@ -22,6 +23,7 @@
import retrofit.http.GET;
import retrofit.http.Headers;
import retrofit.http.POST;
import retrofit.http.Path;
import retrofit.mime.TypedInput;
import retrofit.mime.TypedOutput;
import retrofit.mime.TypedString;
@@ -79,6 +81,7 @@ private interface Example {
@GET("/") Response direct();
@GET("/") void direct(Callback<Response> callback);
@POST("/") Observable<String> observable(@Body String body);
@POST("/{x}/{y}") Observable<Response> observable(@Path("x") String x, @Path("y") String y);
}
private interface InvalidExample extends Example {
}
@@ -536,6 +539,22 @@ public void log(String message) {
verify(onError).call(isA(RetrofitError.class));
}

@Test public void observableHandlesParams() throws Exception {
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
when(mockClient.execute(requestCaptor.capture())) //
.thenReturn(new Response(200, "OK", NO_HEADERS, new TypedString("hello")));
ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
Action1<Response> action = mock(Action1.class);
example.observable("X", "Y").subscribe(action);

Request request = requestCaptor.getValue();
assertThat(request.getUrl()).contains("/X/Y");

verify(action).call(responseCaptor.capture());
Response response = responseCaptor.getValue();
assertThat(response.getStatus()).isEqualTo(200);
}

@Test public void observableUsesHttpExecutor() throws IOException {
Response response = new Response(200, "OK", NO_HEADERS, new TypedString("hello"));
when(mockClient.execute(any(Request.class))).thenReturn(response);

0 comments on commit 033587f

Please sign in to comment.