DATACMNS-1196 - Fixed generics lookup for nested generics in ParameterizedTypeInformation.

We now eagerly resolve a generics declaration chain, which we previously - erroneously - expected GenericTypeResolver to do for us. Simplified TypeVariableTypeInformation implementation. Renamed ParameterizedTypeUnitTests to ParameterizedTypeInformationUnitTests.
This commit is contained in:
Oliver Gierke
2017-10-12 18:04:32 +02:00
parent 9c8aaac0c4
commit 8ce79c1810
4 changed files with 73 additions and 70 deletions

View File

@@ -41,7 +41,7 @@ import org.springframework.core.GenericTypeResolver;
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class ParameterizedTypeUnitTests {
public class ParameterizedTypeInformationUnitTests {
@Mock ParameterizedType one;
Class<?> resolvedOne;
@@ -96,7 +96,7 @@ public class ParameterizedTypeUnitTests {
public void createsToStringRepresentation() {
assertThat(from(Foo.class).getProperty("param").toString())
.isEqualTo("org.springframework.data.util.ParameterizedTypeUnitTests$Localized<java.lang.String>");
.isEqualTo("org.springframework.data.util.ParameterizedTypeInformationUnitTests$Localized<java.lang.String>");
}
@Test // DATACMNS-485
@@ -147,6 +147,14 @@ public class ParameterizedTypeUnitTests {
assertThat(componentType.getType()).isEqualTo(Responsibility.class);
}
@Test // DATACMNS-1196
public void detectsNestedGenerics() {
TypeInformation<?> myList = ClassTypeInformation.from(EnumGeneric.class).getRequiredProperty("inner.myList");
assertThat(myList.getRequiredComponentType().getType()).isEqualTo(MyEnum.class);
}
@SuppressWarnings("serial")
class Localized<S> extends HashMap<Locale, S> {
S value;
@@ -212,4 +220,21 @@ public class ParameterizedTypeUnitTests {
class Candidate {
CandidateInfoContainer<Experience> experiences;
}
// FOO
static abstract class Generic<T> {
Inner<T> inner;
static class Inner<T> {
List<T> myList;
}
}
static class EnumGeneric extends Generic<MyEnum> {}
public enum MyEnum {
E1, E2
}
}