Search { public static List<Method> getAllMethods(Class<?> clazz) { Conditions.notNull(clazz); List<Method> methods = new ArrayList<>(); Class<?> superClazz = clazz.getSuperclass(); if (!superClazz.isAssignableFrom(Object.class)) { methods.addAll(getAllMethods(superClazz)); } for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals("$jacocoInit")) { continue; } methods.add(method); } return methods.stream().distinct().collect(Collectors.toList()); } Search(); static T getInheritedAnnotation(Class<?> clazz, Class<T> annotation); static List<Field> getAllFields(Class<?> clazz); static List<Field> getAllFields(Class<?> clazz, SearchCriteria criteria); static List<Method> getAllMethods(Class<?> clazz);  }
@Test void getAllMethods() throws Exception { assertThrows(IllegalArgumentException.class, () -> Search.getAllMethods(null)); List<Method> methods = Search.getAllMethods(BaseReflectiveSearch.class); assertEquals(1, methods.size()); assertEquals(BaseReflectiveSearch.class.getDeclaredMethod("topMethod"), methods.get(0)); methods = Search.getAllMethods(InheritedReflectiveSearch.class); assertEquals(2, methods.size()); assertTrue(methods.contains(BaseReflectiveSearch.class.getDeclaredMethod("topMethod"))); assertTrue(methods.contains(InheritedReflectiveSearch.class.getDeclaredMethod("bottomMethod"))); methods = Search.getAllMethods(OverridenReflectiveSearch.class); assertEquals(3, methods.size()); assertTrue(methods.contains(BaseReflectiveSearch.class.getDeclaredMethod("topMethod"))); assertTrue(methods.contains(InheritedReflectiveSearch.class.getDeclaredMethod("bottomMethod"))); assertTrue(methods.contains(OverridenReflectiveSearch.class.getDeclaredMethod("topMethod"))); }