1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
37
37
/**
38
38
* @author Juergen Hoeller
39
39
* @author Sam Brannen
40
+ * @author Sebastien Deleuze
40
41
*/
41
42
@ SuppressWarnings ({"unchecked" , "rawtypes" })
42
43
class GenericTypeResolverTests {
@@ -185,6 +186,51 @@ public void resolveTransitiveTypeVariableWithDifferentName() {
185
186
assertThat (resolved ).isEqualTo (E .class );
186
187
}
187
188
189
+ @ Test
190
+ void resolveWildcardTypeWithUpperBound () {
191
+ Method method = findMethod (MySimpleSuperclassType .class , "upperBound" , List .class );
192
+ Type resolved = resolveType (method .getGenericParameterTypes ()[0 ], MySimpleSuperclassType .class );
193
+ ResolvableType resolvableType = ResolvableType .forType (resolved );
194
+ assertThat (resolvableType .hasUnresolvableGenerics ()).isFalse ();
195
+ assertThat (resolvableType .resolveGenerics ()).containsExactly (String .class );
196
+ }
197
+
198
+ @ Test
199
+ void resolveWildcardTypeWithUpperBoundWithResolvedType () {
200
+ Method method = findMethod (MySimpleSuperclassType .class , "upperBoundWithResolvedType" , List .class );
201
+ Type resolved = resolveType (method .getGenericParameterTypes ()[0 ], MySimpleSuperclassType .class );
202
+ ResolvableType resolvableType = ResolvableType .forType (resolved );
203
+ assertThat (resolvableType .hasUnresolvableGenerics ()).isFalse ();
204
+ assertThat (resolvableType .resolveGenerics ()).containsExactly (Integer .class );
205
+ }
206
+
207
+ @ Test
208
+ void resolveWildcardTypeWithLowerBound () {
209
+ Method method = findMethod (MySimpleSuperclassType .class , "lowerBound" , List .class );
210
+ Type resolved = resolveType (method .getGenericParameterTypes ()[0 ], MySimpleSuperclassType .class );
211
+ ResolvableType resolvableType = ResolvableType .forType (resolved );
212
+ assertThat (resolvableType .hasUnresolvableGenerics ()).isFalse ();
213
+ assertThat (resolvableType .resolveGenerics ()).containsExactly (String .class );
214
+ }
215
+
216
+ @ Test
217
+ void resolveWildcardTypeWithLowerBoundWithResolvedType () {
218
+ Method method = findMethod (MySimpleSuperclassType .class , "lowerBoundWithResolvedType" , List .class );
219
+ Type resolved = resolveType (method .getGenericParameterTypes ()[0 ], MySimpleSuperclassType .class );
220
+ ResolvableType resolvableType = ResolvableType .forType (resolved );
221
+ assertThat (resolvableType .hasUnresolvableGenerics ()).isFalse ();
222
+ assertThat (resolvableType .resolveGenerics ()).containsExactly (Integer .class );
223
+ }
224
+
225
+ @ Test
226
+ void resolveWildcardTypeWithUnbounded () {
227
+ Method method = findMethod (MySimpleSuperclassType .class , "unbounded" , List .class );
228
+ Type resolved = resolveType (method .getGenericParameterTypes ()[0 ], MySimpleSuperclassType .class );
229
+ ResolvableType resolvableType = ResolvableType .forType (resolved );
230
+ assertThat (resolvableType .hasUnresolvableGenerics ()).isFalse ();
231
+ assertThat (resolvableType .resolveGenerics ()).containsExactly (Object .class );
232
+ }
233
+
188
234
public interface MyInterfaceType <T > {
189
235
}
190
236
@@ -195,6 +241,21 @@ public class MyCollectionInterfaceType implements MyInterfaceType<Collection<Str
195
241
}
196
242
197
243
public abstract class MySuperclassType <T > {
244
+
245
+ public void upperBound (List <? extends T > list ) {
246
+ }
247
+
248
+ public void upperBoundWithResolvedType (List <? extends Integer > list ) {
249
+ }
250
+
251
+ public void lowerBound (List <? extends T > list ) {
252
+ }
253
+
254
+ public void lowerBoundWithResolvedType (List <? super Integer > list ) {
255
+ }
256
+
257
+ public void unbounded (List <?> list ) {
258
+ }
198
259
}
199
260
200
261
public class MySimpleSuperclassType extends MySuperclassType <String > {
0 commit comments