Author: ggregory
Date: Thu Mar 14 01:35:37 2013
New Revision: 1456305

URL: http://svn.apache.org/r1456305
Log:
[LANG-873] Add FieldUtils getAllFields() to return all the fields defined in 
the given class and super classes. Alternate impl that splits into two APIs, 
one with an array result, the other with a List.

Modified:
    
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java

Modified: 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java?rev=1456305&r1=1456304&r2=1456305&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
 (original)
+++ 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
 Thu Mar 14 01:35:37 2013
@@ -28,6 +28,9 @@ import static org.junit.Assume.assumeNot
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.reflect.testbed.Ambig;
@@ -145,6 +148,26 @@ public class FieldUtilsTest {
         assertEquals(5, FieldUtils.getAllFields(PublicChild.class).length);
     }
 
+    private <T> List<T> asArrayList(T... values) {
+        final ArrayList<T> arrayList = new ArrayList<T>();
+        for (T t : values) {
+            arrayList.add(t);
+        }
+        return arrayList;
+    }
+
+    @Test
+    public void testGetAllFieldsList() {
+        assertEquals(0, FieldUtils.getAllFieldsList(Object.class).size());
+        final List<Field> fieldsNumber = 
asArrayList(Number.class.getDeclaredFields());
+        assertEquals(fieldsNumber, FieldUtils.getAllFieldsList(Number.class));
+        final List<Field> fieldsInteger = 
asArrayList(Integer.class.getDeclaredFields());
+        final List<Field> allFieldsInteger = new 
ArrayList<Field>(fieldsInteger);
+        allFieldsInteger.addAll(fieldsNumber);
+        assertEquals(allFieldsInteger, 
FieldUtils.getAllFieldsList(Integer.class));
+        assertEquals(5, FieldUtils.getAllFieldsList(PublicChild.class).size());
+    }
+
     @Test
     public void testGetDeclaredField() {
         assertNull(FieldUtils.getDeclaredField(PublicChild.class, "VALUE"));


Reply via email to