提交 a12554ea 编写于 作者: J Jake Wharton

Break request creation parsing out of service method

The parsing of annotations which define the shape of a request and the mechnism of request creation is independent of the response converter and call adapter parsing in the return type. Moreover, the request creation part is common to things like web sockets and server-sent events which might be supported in the future where the return type handling is completely different.
上级 8b8887c1
此差异已折叠。
......@@ -25,11 +25,11 @@ import retrofit2.http.GET;
import retrofit2.http.Url;
import static org.assertj.core.api.Assertions.assertThat;
import static retrofit2.RequestBuilderTest.buildRequest;
import static retrofit2.RequestFactoryTest.buildRequest;
@RunWith(RobolectricTestRunner.class)
@SuppressWarnings({"UnusedParameters", "unused"}) // Parameters inspected reflectively.
public final class RequestBuilderAndroidTest {
public final class RequestFactoryAndroidTest {
@Test public void getWithAndroidUriUrl() {
class Example {
@GET
......
......@@ -20,7 +20,8 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public final class ServiceMethodTest {
// TODO this test is far too white box, migrate to black box.
public final class RequestFactoryBuilderTest {
@Test public void pathParameterParsing() throws Exception {
expectParams("/");
expectParams("/foo");
......@@ -41,7 +42,7 @@ public final class ServiceMethodTest {
}
private static void expectParams(String path, String... expected) {
Set<String> calculated = ServiceMethod.parsePathParameters(path);
Set<String> calculated = RequestFactory.Builder.parsePathParameters(path);
assertThat(calculated).containsExactly(expected);
}
}
......@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
......@@ -65,7 +64,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@SuppressWarnings({"UnusedParameters", "unused"}) // Parameters inspected reflectively.
public final class RequestBuilderTest {
public final class RequestFactoryTest {
private static final MediaType TEXT_PLAIN = MediaType.parse("text/plain");
@Test public void customMethodNoBody() {
......@@ -2689,10 +2688,8 @@ public final class RequestBuilderTest {
}
static <T> Request buildRequest(Class<T> cls, Retrofit.Builder builder, Object... args) {
final AtomicReference<Request> requestRef = new AtomicReference<>();
okhttp3.Call.Factory callFactory = new okhttp3.Call.Factory() {
@Override public okhttp3.Call newCall(Request request) {
requestRef.set(request);
throw new UnsupportedOperationException("Not implemented");
}
};
......@@ -2700,13 +2697,8 @@ public final class RequestBuilderTest {
Retrofit retrofit = builder.callFactory(callFactory).build();
Method method = TestingUtils.onlyMethod(cls);
//noinspection unchecked
Call<T> call = (Call<T>) retrofit.loadServiceMethod(method).invoke(args);
try {
call.execute();
throw new AssertionError();
} catch (UnsupportedOperationException ignored) {
return requestRef.get();
return RequestFactory.parseAnnotations(retrofit, method).create(args);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册