diff options
author | Emmanuel Bourg <ebourg@apache.org> | 2017-10-25 11:33:11 +0200 |
---|---|---|
committer | Emmanuel Bourg <ebourg@apache.org> | 2017-10-25 11:33:11 +0200 |
commit | 86ee2f0c49ee1002a7bcd624aa105caba0166617 (patch) | |
tree | 8cbe1246ec1113a082e23057c986bd09a569e5ef /spring-core/src/test/java/org/springframework | |
parent | 0ffebdadce315ab1d00dd5de08d285bbf54a851e (diff) |
New upstream version 4.3.12
Diffstat (limited to 'spring-core/src/test/java/org/springframework')
-rw-r--r-- | spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java | 37 | ||||
-rw-r--r-- | spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java | 18 |
2 files changed, 43 insertions, 12 deletions
diff --git a/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java b/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java index 56060b24..686d5812 100644 --- a/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java +++ b/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,25 +33,40 @@ import static org.junit.Assert.*; public class ParameterizedTypeReferenceTests { @Test - public void map() throws NoSuchMethodException { + public void stringTypeReference() { + ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {}; + assertEquals(String.class, typeReference.getType()); + } + + @Test + public void mapTypeReference() throws Exception { Type mapType = getClass().getMethod("mapMethod").getGenericReturnType(); - ParameterizedTypeReference<Map<Object,String>> mapTypeReference = new ParameterizedTypeReference<Map<Object,String>>() {}; - assertEquals(mapType, mapTypeReference.getType()); + ParameterizedTypeReference<Map<Object,String>> typeReference = new ParameterizedTypeReference<Map<Object,String>>() {}; + assertEquals(mapType, typeReference.getType()); } @Test - public void list() throws NoSuchMethodException { - Type mapType = getClass().getMethod("listMethod").getGenericReturnType(); - ParameterizedTypeReference<List<String>> mapTypeReference = new ParameterizedTypeReference<List<String>>() {}; - assertEquals(mapType, mapTypeReference.getType()); + public void listTypeReference() throws Exception { + Type listType = getClass().getMethod("listMethod").getGenericReturnType(); + ParameterizedTypeReference<List<String>> typeReference = new ParameterizedTypeReference<List<String>>() {}; + assertEquals(listType, typeReference.getType()); } @Test - public void string() { - ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {}; - assertEquals(String.class, typeReference.getType()); + public void reflectiveTypeReferenceWithSpecificDeclaration() throws Exception{ + Type listType = getClass().getMethod("listMethod").getGenericReturnType(); + ParameterizedTypeReference<List<String>> typeReference = ParameterizedTypeReference.forType(listType); + assertEquals(listType, typeReference.getType()); } + @Test + public void reflectiveTypeReferenceWithGenericDeclaration() throws Exception{ + Type listType = getClass().getMethod("listMethod").getGenericReturnType(); + ParameterizedTypeReference<?> typeReference = ParameterizedTypeReference.forType(listType); + assertEquals(listType, typeReference.getType()); + } + + public static Map<Object, String> mapMethod() { return null; } diff --git a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java index 57e77d22..ab903fc6 100644 --- a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java +++ b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -870,6 +870,22 @@ public class ResolvableTypeTests { } @Test + public void resolveTypeVariableFromReflectiveParameterizedTypeReference() throws Exception { + Type sourceType = Methods.class.getMethod("typedReturn").getGenericReturnType(); + ResolvableType type = ResolvableType.forType(ParameterizedTypeReference.forType(sourceType)); + assertThat(type.resolve(), nullValue()); + assertThat(type.getType().toString(), equalTo("T")); + } + + @Test + public void resolveTypeVariableFromDeclaredParameterizedTypeReference() throws Exception { + Type sourceType = Methods.class.getMethod("charSequenceReturn").getGenericReturnType(); + ResolvableType reflectiveType = ResolvableType.forType(sourceType); + ResolvableType declaredType = ResolvableType.forType(new ParameterizedTypeReference<List<CharSequence>>() {}); + assertEquals(reflectiveType, declaredType); + } + + @Test public void toStrings() throws Exception { assertThat(ResolvableType.NONE.toString(), equalTo("?")); |