|
17 | 17 |
|
18 | 18 | import com.google.gson.reflect.TypeToken; |
19 | 19 |
|
| 20 | +import org.assertj.core.api.Fail; |
20 | 21 | import org.junit.Rule; |
21 | 22 | import org.junit.Test; |
22 | 23 | import org.junit.rules.ExpectedException; |
|
26 | 27 | import java.util.LinkedHashMap; |
27 | 28 | import java.util.List; |
28 | 29 | import java.util.Map; |
| 30 | +import java.util.SortedMap; |
29 | 31 |
|
30 | 32 | import static feign.assertj.FeignAssertions.assertThat; |
31 | 33 | import static java.util.Arrays.asList; |
@@ -260,6 +262,40 @@ public void customExpander() throws Exception { |
260 | 262 | .containsExactly(entry(0, DateToMillis.class)); |
261 | 263 | } |
262 | 264 |
|
| 265 | + @Test |
| 266 | + public void queryMap() throws Exception { |
| 267 | + MethodMetadata md = parseAndValidateMetadata(QueryMapTestInterface.class, "queryMap", Map.class); |
| 268 | + |
| 269 | + assertThat(md.queryMapIndex()).isEqualTo(0); |
| 270 | + } |
| 271 | + |
| 272 | + @Test |
| 273 | + public void queryMapMapSubclass() throws Exception { |
| 274 | + MethodMetadata md = parseAndValidateMetadata(QueryMapTestInterface.class, "queryMapMapSubclass", SortedMap.class); |
| 275 | + |
| 276 | + assertThat(md.queryMapIndex()).isEqualTo(0); |
| 277 | + } |
| 278 | + |
| 279 | + @Test |
| 280 | + public void onlyOneQueryMapAnnotationPermitted() throws Exception { |
| 281 | + try { |
| 282 | + parseAndValidateMetadata(QueryMapTestInterface.class, "multipleQueryMap", Map.class, Map.class); |
| 283 | + Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); |
| 284 | + } catch (IllegalStateException ex) { |
| 285 | + assertThat(ex).hasMessage("QueryMap annotation was present on multiple parameters."); |
| 286 | + } |
| 287 | + } |
| 288 | + |
| 289 | + @Test |
| 290 | + public void queryMapMustBeInstanceOfMap() throws Exception { |
| 291 | + try { |
| 292 | + parseAndValidateMetadata(QueryMapTestInterface.class, "nonMapQueryMap", String.class); |
| 293 | + Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); |
| 294 | + } catch (IllegalStateException ex) { |
| 295 | + assertThat(ex).hasMessage("QueryMap parameter must be a Map: class java.lang.String"); |
| 296 | + } |
| 297 | + } |
| 298 | + |
263 | 299 | @Test |
264 | 300 | public void slashAreEncodedWhenNeeded() throws Exception { |
265 | 301 | MethodMetadata md = parseAndValidateMetadata(SlashNeedToBeEncoded.class, |
@@ -392,6 +428,23 @@ public String expand(Object value) { |
392 | 428 | } |
393 | 429 | } |
394 | 430 |
|
| 431 | + interface QueryMapTestInterface { |
| 432 | + |
| 433 | + @RequestLine("POST /") |
| 434 | + void queryMap(@QueryMap Map<String, String> queryMap); |
| 435 | + |
| 436 | + @RequestLine("POST /") |
| 437 | + void queryMapMapSubclass(@QueryMap SortedMap<String, String> queryMap); |
| 438 | + |
| 439 | + // invalid |
| 440 | + @RequestLine("POST /") |
| 441 | + void multipleQueryMap(@QueryMap Map<String, String> mapOne, @QueryMap Map<String, String> mapTwo); |
| 442 | + |
| 443 | + // invalid |
| 444 | + @RequestLine("POST /") |
| 445 | + void nonMapQueryMap(@QueryMap String notAMap); |
| 446 | + } |
| 447 | + |
395 | 448 | interface SlashNeedToBeEncoded { |
396 | 449 | @RequestLine(value = "GET /api/queues/{vhost}", decodeSlash = false) |
397 | 450 | String getQueues(@Param("vhost") String vhost); |
|
0 commit comments