/** * Test that types with infinite recursion don't cause us to bomb out. In this case we use Enum, * as Enum<E> has E extend Enum<E>. */ public void testEnumInfiniteRecursion() { JavaUtils ju = JavaUtils.getJavaUtils(); try { Class<?> enumClass = getClass().getClassLoader().loadClass("java.lang.Enum"); ju.getTypeParams(enumClass); } catch (ClassNotFoundException cnfe) { } // ok test passed }
public void testRecursiveTpar() throws Exception { Class<?> colClass = java.util.Collections.class; Method minMethod = colClass.getMethod("min", Collection.class); JavaUtils ju = JavaUtils.getJavaUtils(); List<GenTypeDeclTpar> rlist = ju.getTypeParams(minMethod); assertEquals(1, rlist.size()); GenTypeDeclTpar tvar = rlist.get(0); GenTypeSolid bound = tvar.getBound(); assertEquals("java.lang.Comparable<? super T>", bound.toString()); GenTypeSolid[] ubounds = bound.getUpperBounds(); assertEquals(2, ubounds.length); // should be Object and Comparable GenTypeClass boundClass = bound.getUpperBounds()[1].asClass(); List<? extends GenTypeParameter> tpars = boundClass.getTypeParamList(); assertEquals(1, tpars.size()); GenTypeParameter tparOne = tpars.get(0); GenTypeSolid shouldBeT = tparOne.getLowerBound(); assertNotNull(shouldBeT); Set<Reflective> s = new HashSet<Reflective>(); shouldBeT.erasedSuperTypes(s); assertTrue(s.size() > 0); boolean foundComparable = false; for (Reflective r : s) { if (r.getName().equals("java.lang.Comparable")) { foundComparable = true; break; } } assertTrue(foundComparable); }