ReflectionUtils { public static List<Field> getAllDeclaredFields(Class<?> type) { List<Field> fields = new ArrayList<Field>(); for (Class<?> baseType = type; baseType != null; baseType = baseType.getSuperclass()) { fields.addAll(Arrays.asList(baseType.getDeclaredFields())); } return fields; } 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_getAllDeclaredFieldsFromBaseClass() { List<Field> fields = getAllDeclaredFields(BaseClassToExamine.class); assertEquals(2, fields.size()); Collections.sort(fields, new FieldByNameComparator()); assertEquals("stringBase", fields.get(0).getName()); assertEquals("textFieldBase", fields.get(1).getName()); }
@Test public void test_getAllDeclaredFieldsFromSubClass() { List<Field> fields = getAllDeclaredFields(SubClassToExamine.class); assertEquals(4, fields.size()); Collections.sort(fields, new FieldByNameComparator()); assertEquals("stringBase", fields.get(0).getName()); assertEquals("stringSub", fields.get(1).getName()); assertEquals("textFieldBase", fields.get(2).getName()); assertEquals("textFieldSub", fields.get(3).getName()); }