Search { public static List<Field> getAllFields(Class<?> clazz) { Conditions.notNull(clazz); List<Field> fields = new ArrayList<>(); Class<?> superClazz = clazz.getSuperclass(); if (!superClazz.isAssignableFrom(Object.class)) { fields.addAll(getAllFields(superClazz)); } addFields(fields, clazz); return fields; } 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 getAllFields() throws Exception { assertThrows(IllegalArgumentException.class, () -> Search.getAllFields(null)); List<Field> fields = Search.getAllFields(BaseReflectiveSearch.class); assertEquals(1, fields.size()); assertEquals(BaseReflectiveSearch.class.getDeclaredField("topField"), fields.get(0)); fields = Search.getAllFields(InheritedReflectiveSearch.class); assertEquals(2, fields.size()); assertTrue(fields.contains(BaseReflectiveSearch.class.getDeclaredField("topField"))); assertTrue(fields.contains(InheritedReflectiveSearch.class.getDeclaredField("bottomField"))); fields = Search.getAllFields(OverridenReflectiveSearch.class); assertEquals(2, fields.size()); assertTrue(fields.contains(BaseReflectiveSearch.class.getDeclaredField("topField"))); assertTrue(fields.contains(InheritedReflectiveSearch.class.getDeclaredField("bottomField"))); }