ReflectUtil { public static List<Field> getAllDeclaredFields(Class<?> clazz) { List<Field> fieldList = new LinkedList<>(); fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); if (clazz.getSuperclass() != null) { fieldList.addAll(getAllDeclaredFields(clazz.getSuperclass())); } return fieldList; }  static List<Field> getAllDeclaredFields(Class<?> clazz); static List<Method> getAllDeclaredMethods(Class<?> clazz); static @Nullable Annotation findQualifierAnnotation(Field field); static @Nullable Annotation findQualifierAnnotation(Annotation[] annotations, String description); static boolean isAnyAnnotationPresent(Field field, Collection<Class<? extends Annotation>> annotations); static boolean isAnyAnnotationPresent(Method method, Collection<Class<? extends Annotation>> annotations);  }
@Test public void testGetAllDeclaredFields() { List<Field> fields = ReflectUtil.getAllDeclaredFields(SubclassTestObject.class); assertThat(fields).hasSize(4); assertFieldInList(fields, "subclassString", String.class); assertFieldInList(fields, "superclassTestString", String.class); assertFieldInList(fields, "subclassInnterClass", SubclassTestObject.SubClassInnerClass.class); assertFieldInList(fields, "superclassInnerClass", SuperclassTestObject.SuperClassInnerClass.class); }