ReflectionUtils { public static List<Method> findMethods(Class<?> clazz, String nameRegex, ParamCount numberOfParams) { Pattern p = Pattern.compile(nameRegex); Matcher m = p.matcher(""); List<Method> methods = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { if (numberOfParams.matches(method.getParameterTypes().length) && m.reset(method.getName()).matches()) { methods.add(method); } } return methods; } private  ReflectionUtils(); static List<Method> findMethods(Class<?> clazz, String nameRegex,
            ParamCount numberOfParams); static List<Method> findMethods(Class<?> clazz, String nameRegex,
            Class<?>... paramTypes); static boolean isComponent(Class<?> componentClass); static List<Field> getAllDeclaredFields(Class<?> type); static List<Field> getAllDeclaredFieldsAnnotatedWith(Class<?> type,
            Class<? extends Annotation> annotationType); static List<Method> getAllDeclaredMethods(Class<?> type); static List<Method> getAllDeclaredMethodsAnnotatedWith(Class<?> type,
            Class<? extends Annotation> annotationType);  }
@Test public void test_findMethodsByRegexAndType() { assertEquals( 1, findMethods(SubClassToExamine.class, "setFoo(.*)", String.class) .size()); }
@Test public void test_findMethodsByRegexAndTypeUsingAny() { assertEquals( 1, findMethods( SubClassToExamine.class, "setFoo(.*)", new Class<?>[] { String.class, AnyClassOrPrimitive.class }).size()); }
@Test public void test_findMethodsByRegexAndTypeAsNull() { assertEquals( 1, findMethods(SubClassToExamine.class, "setFoo(.*)", (Class<?>[]) null).size()); }
@Test public void test_findMethodsByRegExAndParamCount() { assertEquals( 4, findMethods(SubClassToExamine.class, "setFoo(.*)", ParamCount.fromTo(0, 2)).size()); }
@Test public void test_findMethodsByConstantParamCount_constant0() { assertEquals( 1, findMethods(SubClassToExamine.class, "setFooBar", ParamCount.constant(0)).size()); }
@Test public void test_findMethodsByConstantParamCount_constant1() { assertEquals( 2, findMethods(SubClassToExamine.class, "setFooBar", ParamCount.constant(1)).size()); }
@Test public void test_findMethodsByConstantParamCount_constant2() { assertEquals( 1, findMethods(SubClassToExamine.class, "setFooBar", ParamCount.constant(2)).size()); }
@Test public void test_findMethodsByConstantParamCount_constant3() { assertEquals( 0, findMethods(SubClassToExamine.class, "setFooBar", ParamCount.constant(3)).size()); }