### Question:
ClassUtils { public static <T> List<Class<?>> getTypeArguments( Class<T> baseClass, Class<? extends T> childClass) { Map<Type, Type> resolvedTypes = new HashMap<Type, Type>(); Type type = childClass; Class typeClass = getClass(type); while (!typeClass.equals(baseClass)) { if (type instanceof Class) { type = ((Class) type).getGenericSuperclass(); } else { ParameterizedType parameterizedType = (ParameterizedType) type; Class<?> rawType = (Class) parameterizedType.getRawType(); Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); TypeVariable<?>[] typeParameters = rawType.getTypeParameters(); for (int i = 0; i < actualTypeArguments.length; i++) { resolvedTypes.put(typeParameters[i], actualTypeArguments[i]); } if (!rawType.equals(baseClass)) { type = rawType.getGenericSuperclass(); } } typeClass = getClass(type); if (typeClass == null) { throw new IllegalArgumentException("Unable to find the class for the type " + type); } } Type[] actualTypeArguments; if (type instanceof Class) { actualTypeArguments = ((Class) type).getTypeParameters(); } else { actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments(); } List<Class<?>> typeArgumentsAsClasses = new ArrayList<Class<?>>(); for (Type baseType : actualTypeArguments) { while (resolvedTypes.containsKey(baseType)) { baseType = resolvedTypes.get(baseType); } typeArgumentsAsClasses.add(getClass(baseType)); } return typeArgumentsAsClasses; } private  ClassUtils(); static Set<Class> findAllTypes(Class cls); static void findAllTypes(Class cls, Set<Class> types); static List<Class<?>> getTypeArguments(
            Class<T> baseClass, Class<? extends T> childClass);  }### Answer:
@Test public void testGetTypeArguments() { assertEquals(asList(String.class), ClassUtils.getTypeArguments(BaseClass.class, Child.class)); assertEquals(asList(String.class), ClassUtils.getTypeArguments(BaseClass.class, Baby.class)); assertEquals(singletonList(null), ClassUtils.getTypeArguments(BaseClass.class, ForgotType.class)); }
@Test(expected = IllegalArgumentException.class) public void testGetTypeArgumentsChildNotSubclass() { Class fakeChild = BaseClass.class; ClassUtils.getTypeArguments(Baby.class, (Class<? extends Baby>) fakeChild); }