@@ -0,0 +1,2445 @@
+package com.googlecode.gentyref;%0A%0Aimport java.lang.reflect.Method;%0Aimport java.lang.reflect.ParameterizedType;%0Aimport java.lang.reflect.Type;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Aimport junit.framework.TestCase;%0A%0A/**%0A * Test for http://code.google.com/p/gentyref/issues/detail?id=3%0A */%0Apublic class Issue3Test extends TestCase %7B%0A%09public class NamedDataObject %7B%0A%09%7D%0A%0A%09public abstract class HierarchicalNamedDataObject%3CRealClass extends HierarchicalNamedDataObject%3CRealClass%3E%3E extends NamedDataObject %7B%0A%09%09private RealClass parent;%0A%0A%09%09private List%3CRealClass%3E children = new ArrayList%3CRealClass%3E();%0A%0A%09%09public List%3CRealClass%3E getChildren() %7B%0A%09%09%09return children;%0A%09%09%7D%0A%0A%09%09public RealClass getParent() %7B%0A%09%09%09return parent;%0A%09%09%7D%0A%09%7D%0A%0A%09public void testIt() throws NoSuchMethodException %7B%0A%09%09// the return type for the raw type is a raw list%0A%09%09Method getChildren = HierarchicalNamedDataObject.class.getMethod(%22getChildren%22);%0A%09%09assertEquals(List.class, GenericTypeReflector.getExactReturnType(getChildren,%0A%09%09%09%09HierarchicalNamedDataObject.class));%0A%09%09%0A%09%09// the return type for HierarchicalNamedDataObject%3C?%3E (constructed using addWildcardParameters)%0A%09%09//  is a capture of a list whos element type is a HierarchicalNamedDataObject%0A%09%09Type returnType = GenericTypeReflector.getExactReturnType(getChildren, GenericTypeReflector%0A%09%09%09%09.addWildcardParameters(HierarchicalNamedDataObject.class));%0A%09%09%0A%09%09Type listType = ((ParameterizedType)returnType).getActualTypeArguments()%5B0%5D;%0A%09%09assertTrue(listType instanceof CaptureType);%0A%09%09Type listElementType = ((CaptureType)listType).getUpperBounds()%5B0%5D;%0A%09%09assertTrue(listElementType instanceof ParameterizedType);%0A%09%09assertEquals(HierarchicalNamedDataObject.class, ((ParameterizedType)listElementType).getRawType());%0A%0A%09%09// using getCollectionElementTypes, you can directly get the classes&interfaces contained in the list%0A%09%09assertEquals(Arrays.%3CClass%3C?%3E%3EasList(HierarchicalNamedDataObject.class), getCollectionElementTypes(getChildren, HierarchicalNamedDataObject.class));%0A%09%7D%0A%09%0A%09private List%3CClass%3C?%3E%3E getCollectionElementTypes(Method getter, Class%3C?%3E clazz) %7B%0A%09%09return GenericTypeReflector.getUpperBoundClassAndInterfaces(%0A%09%09%09%09GenericTypeReflector.getTypeParameter(%0A%09%09%09%09%09%09GenericTypeReflector.getExactReturnType(getter, GenericTypeReflector.addWildcardParameters(HierarchicalNamedDataObject.class)),%0A%09%09%09%09%09%09Collection.class.getTypeParameters()%5B0%5D%0A%09%09%09%09)%0A%09%09);%0A%09%7D%0A%0A%7D%0A

Add test for the example given in Issue #3