|
35 | 35 | import okhttp3.mockwebserver.MockWebServer; |
36 | 36 | import static java.util.Arrays.asList; |
37 | 37 | import static org.assertj.core.api.Assertions.assertThat; |
| 38 | +import static org.assertj.core.api.Assertions.entry; |
38 | 39 | import static org.junit.Assert.assertEquals; |
39 | 40 | import static feign.Util.UTF_8; |
40 | 41 |
|
@@ -93,7 +94,7 @@ public void parsesRequestAndResponse() throws IOException, InterruptedException |
93 | 94 |
|
94 | 95 | MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("POST") |
95 | 96 | .hasPath("/?foo=bar&foo=baz&qux=") |
96 | | - .hasHeaders("Foo: Bar", "Foo: Baz", "Qux: ", "Accept: */*", "Content-Length: 3") |
| 97 | + .hasHeaders("Foo: Bar", "Foo: Baz", "Accept: */*", "Content-Length: 3") |
97 | 98 | .hasBody("foo"); |
98 | 99 | } |
99 | 100 |
|
@@ -282,6 +283,38 @@ public void testDefaultCollectionFormat() throws Exception { |
282 | 283 | .hasPath("/?foo=bar&foo=baz"); |
283 | 284 | } |
284 | 285 |
|
| 286 | + @Test |
| 287 | + public void testHeadersWithNullParams() throws InterruptedException { |
| 288 | + server.enqueue(new MockResponse().setBody("body")); |
| 289 | + |
| 290 | + TestInterface api = newBuilder() |
| 291 | + .target(TestInterface.class, "http://localhost:" + server.getPort()); |
| 292 | + |
| 293 | + Response response = api.getWithHeaders(null); |
| 294 | + |
| 295 | + assertThat(response.status()).isEqualTo(200); |
| 296 | + assertThat(response.reason()).isEqualTo("OK"); |
| 297 | + |
| 298 | + MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET") |
| 299 | + .hasPath("/").hasNoHeaderNamed("Authorization"); |
| 300 | + } |
| 301 | + |
| 302 | + @Test |
| 303 | + public void testHeadersWithNotEmptyParams() throws InterruptedException { |
| 304 | + server.enqueue(new MockResponse().setBody("body")); |
| 305 | + |
| 306 | + TestInterface api = newBuilder() |
| 307 | + .target(TestInterface.class, "http://localhost:" + server.getPort()); |
| 308 | + |
| 309 | + Response response = api.getWithHeaders("token"); |
| 310 | + |
| 311 | + assertThat(response.status()).isEqualTo(200); |
| 312 | + assertThat(response.reason()).isEqualTo("OK"); |
| 313 | + |
| 314 | + MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET") |
| 315 | + .hasPath("/").hasHeaders(entry("authorization", asList("token"))); |
| 316 | + } |
| 317 | + |
285 | 318 | @Test |
286 | 319 | public void testAlternativeCollectionFormat() throws Exception { |
287 | 320 | server.enqueue(new MockResponse().setBody("body")); |
@@ -316,6 +349,12 @@ public interface TestInterface { |
316 | 349 | @RequestLine("GET /?foo={multiFoo}") |
317 | 350 | Response get(@Param("multiFoo") List<String> multiFoo); |
318 | 351 |
|
| 352 | + @Headers({ |
| 353 | + "Authorization: {authorization}" |
| 354 | + }) |
| 355 | + @RequestLine("GET /") |
| 356 | + Response getWithHeaders(@Param("authorization") String authorization); |
| 357 | + |
319 | 358 | @RequestLine(value = "GET /?foo={multiFoo}", collectionFormat = CollectionFormat.CSV) |
320 | 359 | Response getCSV(@Param("multiFoo") List<String> multiFoo); |
321 | 360 |
|
|
0 commit comments