|
25 | 25 | import java.net.URI; |
26 | 26 | import java.nio.charset.StandardCharsets; |
27 | 27 | import java.util.LinkedHashSet; |
| 28 | +import java.util.List; |
28 | 29 | import java.util.Optional; |
29 | 30 | import java.util.Set; |
30 | 31 | import java.util.function.BiFunction; |
@@ -103,6 +104,12 @@ void shutdown() { |
103 | 104 | @interface ParameterizedAdapterTest { |
104 | 105 | } |
105 | 106 |
|
| 107 | + public static Stream<Object> wildcardCases() { |
| 108 | + return Stream.of( |
| 109 | + (Function<PersonClient, List<? extends Person>>) BaseClient::getListWildcardUpperBound1, |
| 110 | + (Function<PersonClient, List<? extends Person>>) BaseClient::getListWildcardUpperBound2); |
| 111 | + } |
| 112 | + |
106 | 113 | public static Stream<Object[]> arguments() throws IOException { |
107 | 114 | return Stream.of( |
108 | 115 | createArgsForAdapter((url, or) -> { |
@@ -216,6 +223,15 @@ void getEntityWithGenericReturnType() { |
216 | 223 | assertThat(entity.getBody().name()).isEqualTo("Karl"); |
217 | 224 | } |
218 | 225 |
|
| 226 | + @ParameterizedTest |
| 227 | + @MethodSource("wildcardCases") |
| 228 | + void getWildcardReturnType(Function<PersonClient, List<? extends Person>> invocation) { |
| 229 | + PersonClient client = initService(PersonClient.class); |
| 230 | + prepareResponse(r -> r.setHeader("Content-Type", "application/json").body("[{\"name\":\"Karl\"}]")); |
| 231 | + List<? extends Person> list = invocation.apply(client); |
| 232 | + assertThat(list.get(0).name()).isEqualTo("Karl"); |
| 233 | + } |
| 234 | + |
219 | 235 | @ParameterizedAdapterTest |
220 | 236 | void getWithUriBuilderFactory(MockWebServer server, Service service) throws InterruptedException { |
221 | 237 | prepareResponse(builder -> |
@@ -467,6 +483,12 @@ private interface BaseClient<T> { |
467 | 483 | @GetExchange |
468 | 484 | T getBody(); |
469 | 485 |
|
| 486 | + @GetExchange |
| 487 | + List<? extends T> getListWildcardUpperBound1(); |
| 488 | + |
| 489 | + @GetExchange |
| 490 | + List<? extends Person> getListWildcardUpperBound2(); |
| 491 | + |
470 | 492 | @GetExchange |
471 | 493 | ResponseEntity<T> getEntity(); |
472 | 494 | } |
|
0 commit comments