### Question:
ClassUtils { public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) { Method exactMethod = extractMethod(clazz, sourceMethod); if (exactMethod == null) { String methodName = sourceMethod.getName(); Class<?>[] parameterTypes = sourceMethod.getParameterTypes(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && allSameType(method.getParameterTypes(), parameterTypes)) { return method; } } return null; } else { return exactMethod; } } private  ClassUtils(); static ClassLoader getClassLoader(Object o); static boolean isProxyableClass(Type type); static Class<T> tryToLoadClassForName(String name, Class<T> targetType); static Class<T> tryToLoadClassForName(String name, Class<T> targetType, ClassLoader classLoader); static Class tryToLoadClassForName(String name); static Class tryToLoadClassForName(String name, ClassLoader classLoader); static Class loadClassForName(String name); static T tryToInstantiateClass(Class<T> targetClass); static T tryToInstantiateClassForName(String className, Class<T> targetType); static Object tryToInstantiateClassForName(String className); static Object instantiateClassForName(String className); static String getJarVersion(Class targetClass); static String getRevision(Class targetClass); static boolean containsMethod(Class<?> targetClass, Method method); static Method extractMethod(Class<?> clazz, Method sourceMethod); static boolean containsPossiblyGenericMethod(Class<?> targetClass, Method method); static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod); static boolean returns(Method method, Class<?> clazz);  }### Answer:
@Test public void shouldNotRetrieveMethodBasedOnSameReturnType() throws Exception { Method m = InnerTwo.class.getMethod("getCollection"); Method method = ClassUtils.extractPossiblyGenericMethod(InnerOne.class, m); Assert.assertEquals(InnerOne.class.getMethod("getCollection"), method); }
@Test public void shouldRetrieveMethodBasedOnCastableType() throws Exception { Method m = InnerThree.class.getMethod("getCollection"); Method method = ClassUtils.extractPossiblyGenericMethod(InnerOne.class, m); Assert.assertEquals(InnerOne.class.getMethod("getCollection"), method); }