MCPcopy
hub / github.com/square/retrofit / CallTest

Class CallTest

retrofit/java-test/src/test/java/retrofit2/CallTest.java:53–1521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51import retrofit2.http.Streaming;
52
53public final class CallTest {
54 @Rule public final MockWebServer server = new MockWebServer();
55
56 interface Service {
57 @GET("/")
58 Call<String> getString();
59
60 @GET("/")
61 Call<ResponseBody> getBody();
62
63 @GET("/")
64 @Streaming
65 Call<ResponseBody> getStreamingBody();
66
67 @POST("/")
68 Call<String> postString(@Body String body);
69
70 @POST("/{a}")
71 Call<String> postRequestBody(@Path("a") Object a);
72 }
73
74 @Test
75 public void http200Sync() throws IOException {
76 Retrofit retrofit =
77 new Retrofit.Builder()
78 .baseUrl(server.url("/"))
79 .addConverterFactory(new ToStringConverterFactory())
80 .build();
81 Service example = retrofit.create(Service.class);
82
83 server.enqueue(new MockResponse().setBody("Hi"));
84
85 Response<String> response = example.getString().execute();
86 assertThat(response.isSuccessful()).isTrue();
87 assertThat(response.body()).isEqualTo("Hi");
88 }
89
90 @Test
91 public void http200Async() throws InterruptedException {
92 Retrofit retrofit =
93 new Retrofit.Builder()
94 .baseUrl(server.url("/"))
95 .addConverterFactory(new ToStringConverterFactory())
96 .build();
97 Service example = retrofit.create(Service.class);
98
99 server.enqueue(new MockResponse().setBody("Hi"));
100
101 final AtomicReference<Response<String>> responseRef = new AtomicReference<>();
102 final CountDownLatch latch = new CountDownLatch(1);
103 example
104 .getString()
105 .enqueue(
106 new Callback<String>() {
107 @Override
108 public void onResponse(Call<String> call, Response<String> response) {
109 responseRef.set(response);
110 latch.countDown();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…