|
17 | 17 |
|
18 | 18 | import static org.junit.Assert.*;
|
19 | 19 |
|
| 20 | +import java.lang.reflect.GenericArrayType; |
20 | 21 | import java.lang.reflect.Method;
|
21 | 22 | import java.lang.reflect.ParameterizedType;
|
22 | 23 | import java.lang.reflect.Type;
|
@@ -116,6 +117,18 @@ public void testReturn_SimpleArray() throws Exception {
|
116 | 117 | assertEquals(String.class, resultClass.getComponentType());
|
117 | 118 | }
|
118 | 119 |
|
| 120 | + @Test |
| 121 | + public void testReturn_SimpleArrayOfArray() throws Exception { |
| 122 | + Class<?> clazz = Level1Mapper.class; |
| 123 | + Method method = clazz.getMethod("simpleSelectArrayOfArray"); |
| 124 | + Type result = TypeParameterResolver.resolveReturnType(method, clazz); |
| 125 | + assertTrue(result instanceof Class); |
| 126 | + Class<?> resultClass = (Class<?>) result; |
| 127 | + assertTrue(resultClass.isArray()); |
| 128 | + assertTrue(resultClass.getComponentType().isArray()); |
| 129 | + assertEquals(String.class, resultClass.getComponentType().getComponentType()); |
| 130 | + } |
| 131 | + |
119 | 132 | @Test
|
120 | 133 | public void testReturn_SimpleTypeVar() throws Exception {
|
121 | 134 | Class<?> clazz = Level1Mapper.class;
|
@@ -188,6 +201,43 @@ public void testReturn_Lv1List() throws Exception {
|
188 | 201 | assertEquals(String.class, type.getActualTypeArguments()[0]);
|
189 | 202 | }
|
190 | 203 |
|
| 204 | + @Test |
| 205 | + public void testReturn_Lv1Array() throws Exception { |
| 206 | + Class<?> clazz = Level1Mapper.class; |
| 207 | + Method method = clazz.getMethod("selectArray"); |
| 208 | + Type result = TypeParameterResolver.resolveReturnType(method, clazz); |
| 209 | + assertTrue(result instanceof Class); |
| 210 | + Class<?> resultClass = (Class<?>) result; |
| 211 | + assertTrue(resultClass.isArray()); |
| 212 | + assertEquals(String.class, resultClass.getComponentType()); |
| 213 | + } |
| 214 | + |
| 215 | + @Test |
| 216 | + public void testReturn_Lv2ArrayOfArray() throws Exception { |
| 217 | + Class<?> clazz = Level2Mapper.class; |
| 218 | + Method method = clazz.getMethod("selectArrayOfArray"); |
| 219 | + Type result = TypeParameterResolver.resolveReturnType(method, clazz); |
| 220 | + assertTrue(result instanceof Class); |
| 221 | + Class<?> resultClass = (Class<?>) result; |
| 222 | + assertTrue(result instanceof Class); |
| 223 | + assertTrue(resultClass.isArray()); |
| 224 | + assertTrue(resultClass.getComponentType().isArray()); |
| 225 | + assertEquals(String.class, resultClass.getComponentType().getComponentType()); |
| 226 | + } |
| 227 | + |
| 228 | + @Test |
| 229 | + public void testReturn_Lv2ArrayOfList() throws Exception { |
| 230 | + Class<?> clazz = Level2Mapper.class; |
| 231 | + Method method = clazz.getMethod("selectArrayOfList"); |
| 232 | + Type result = TypeParameterResolver.resolveReturnType(method, clazz); |
| 233 | + assertTrue(result instanceof GenericArrayType); |
| 234 | + GenericArrayType genericArrayType = (GenericArrayType) result; |
| 235 | + assertTrue(genericArrayType.getGenericComponentType() instanceof ParameterizedType); |
| 236 | + ParameterizedType paramType = (ParameterizedType) genericArrayType.getGenericComponentType(); |
| 237 | + assertEquals(List.class, paramType.getRawType()); |
| 238 | + assertEquals(String.class, paramType.getActualTypeArguments()[0]); |
| 239 | + } |
| 240 | + |
191 | 241 | @Test
|
192 | 242 | public void testReturn_Lv2WildcardList() throws Exception {
|
193 | 243 | Class<?> clazz = Level2Mapper.class;
|
|
0 commit comments