ReflectionUtils { public static List<Method> getAllDeclaredMethods(Class<?> type) { List<Method> methods = new ArrayList<Method>(); for (Class<?> baseType = type; baseType != null; baseType = baseType.getSuperclass()) { methods.addAll(Arrays.asList(baseType.getDeclaredMethods())); } 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_getAllDeclaredMethodsFromBaseClass() { List<Method> methods = getAllDeclaredMethods(BaseClassToExamine.class); assertEquals(15, methods.size()); methods.removeAll(getAllDeclaredMethods(Object.class)); assertEquals(3, methods.size()); Collections.sort(methods, new MethodByNameComparator()); assertEquals("getDataFromBase", methods.get(0).getName()); assertEquals("onValueChangedBase", methods.get(1).getName()); assertEquals("setFooBar", methods.get(2).getName()); }
@Test public void test_getAllDeclaredMethodsFromSubClass() { List<Method> methods = getAllDeclaredMethods(SubClassToExamine.class); assertEquals(20, methods.size()); methods.removeAll(getAllDeclaredMethods(Object.class)); assertEquals(8, methods.size()); Collections.sort(methods, new MethodByNameComparator()); assertEquals("getDataFromBase", methods.get(0).getName()); assertEquals("getDataFromSub", methods.get(1).getName()); assertEquals("onValueChangedBase", methods.get(2).getName()); assertEquals("onValueChangedSub", methods.get(3).getName()); assertEquals("setFooBar", methods.get(4).getName()); assertEquals("setFooBar", methods.get(5).getName()); assertEquals("setFooBar", methods.get(6).getName()); assertEquals("setFooBar", methods.get(7).getName()); }