Skip to content

Commit 0802581

Browse files
committed
Unit test for identifying type variable argument
See gh-27748
1 parent d7b9270 commit 0802581

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1159,6 +1159,20 @@ void isAssignableFromForComplexWildcards() throws Exception {
11591159
assertThatResolvableType(complex4).isNotAssignableFrom(complex3);
11601160
}
11611161

1162+
@Test
1163+
void identifyTypeVariable() throws Exception {
1164+
Method method = ClassArguments.class.getMethod("typedArgumentFirst", Class.class, Class.class, Class.class);
1165+
ResolvableType returnType = ResolvableType.forMethodReturnType(method, ClassArguments.class);
1166+
1167+
ResolvableType arg0 = ResolvableType.forMethodParameter(method, 0, ClassArguments.class);
1168+
ResolvableType arg1 = ResolvableType.forMethodParameter(method, 1, ClassArguments.class);
1169+
ResolvableType arg2 = ResolvableType.forMethodParameter(method, 2, ClassArguments.class);
1170+
1171+
assertThat(returnType.getType().equals(arg0.as(Class.class).getGeneric(0).getType())).isTrue();
1172+
assertThat(returnType.getType().equals(arg1.as(Class.class).getGeneric(0).getType())).isFalse();
1173+
assertThat(returnType.getType().equals(arg2.as(Class.class).getGeneric(0).getType())).isFalse();
1174+
}
1175+
11621176
@Test
11631177
void hashCodeAndEquals() throws Exception {
11641178
ResolvableType forClass = ResolvableType.forClass(List.class);
@@ -1427,6 +1441,10 @@ interface Methods<T> {
14271441
}
14281442

14291443

1444+
interface TypedMethods extends Methods<String> {
1445+
}
1446+
1447+
14301448
static class AssignmentBase<O, C, S> {
14311449

14321450
public O o;
@@ -1479,7 +1497,9 @@ static class Assignment extends AssignmentBase<Object, CharSequence, String> {
14791497
}
14801498

14811499

1482-
interface TypedMethods extends Methods<String> {
1500+
interface ClassArguments {
1501+
1502+
<T> T typedArgumentFirst(Class<T> arg0, Class<?> arg1, Class<Object> arg2);
14831503
}
14841504

14851505

0 commit comments

Comments
 (0)