ClassLibrary { public static boolean hasMethod(Class<?> aClass, String methodName, List<? extends Class<?>> parameterTypes) { boolean hasMethod; try { aClass.getMethod(methodName, parameterTypes.toArray(new Class[parameterTypes.size()])); hasMethod = true; } catch (NoSuchMethodException e) { hasMethod = false; } catch (SecurityException e) { hasMethod = true; } return hasMethod; }  static T newInstance(Class<T> theClass); static Object invoke(Method method, Object receiver, Object... arguments); static Object invokeTrespassing(Method method, Object receiver, Object... arguments); static boolean hasMethod(Class<?> aClass, String methodName, List<? extends Class<?>> parameterTypes); static Method method(String methodName, Class<?> aClass, Class<?>... argumentClasses); static boolean isInstanceOf(Class<?> aClass, Object object); static boolean isSuperclassOf(Class<?> subclass, Class<?> thisClass); static boolean isSubclassOf(Class<?> superclass, Class<?> thisClass); static boolean isAbstract(Class<?> aClass); static boolean isGreaterThan(T compared, T inRelationTo); static boolean isLessThan(T compared, T inRelationTo); @SuppressWarnings("unchecked") static int comparison(T one, T other);  }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void hasMethodCheck() { assertTrue(hasMethod(Class.class, "getMethod", (List) asList(String.class, Class[].class))); assertTrue(hasMethod(String.class, "replaceAll", (List) asList(String.class, String.class))); assertFalse(hasMethod(String.class, "replaceWithARegexOrDie", (List) asList(String.class))); }