commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1142555 - in /commons/proper/lang/trunk: RELEASE-NOTES.txt src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java src/site/changes/changes.xml src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
Date Mon, 04 Jul 2011 06:18:27 GMT
Author: ggregory
Date: Mon Jul  4 06:18:26 2011
New Revision: 1142555

URL: http://svn.apache.org/viewvc?rev=1142555&view=rev
Log:
[LANG-713] [patch] Increase test coverage of FieldUtils read methods and tweak javadoc. Apply
patch.

Modified:
    commons/proper/lang/trunk/RELEASE-NOTES.txt
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
    commons/proper/lang/trunk/src/site/changes/changes.xml
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java

Modified: commons/proper/lang/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/RELEASE-NOTES.txt?rev=1142555&r1=1142554&r2=1142555&view=diff
==============================================================================
--- commons/proper/lang/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/lang/trunk/RELEASE-NOTES.txt Mon Jul  4 06:18:26 2011
@@ -103,6 +103,7 @@ IMPROVEMENTS IN 3.0
     [LANG-668] Change ObjectUtils min() & max() functions to use varargs rather than
just two parameters
     [LANG-681] Push down WordUtils to "text" sub-package.
     [LANG-711] Add includeantruntime=false to javac targets to quell warnings in ant 1.8.1
and better (and modest performance gain).
+    [LANG-713] Increase test coverage of FieldUtils read methods and tweak javadoc
 
 BUG FIXES IN 3.0
 ================

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java?rev=1142555&r1=1142554&r2=1142555&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
Mon Jul  4 06:18:26 2011
@@ -217,7 +217,7 @@ public class FieldUtils {
      * @param cls  the class to reflect, must not be null
      * @param fieldName  the field name to obtain
      * @return the value of the field
-     * @throws IllegalArgumentException if the class or field name is null
+     * @throws IllegalArgumentException if the class is null, the field name is null or if
the field could not be found
      * @throws IllegalAccessException if the field is not accessible
      */
     public static Object readStaticField(Class<?> cls, String fieldName) throws IllegalAccessException
{
@@ -232,7 +232,7 @@ public class FieldUtils {
      *  <code>setAccessible</code> method. <code>False</code> will
only
      *  match public fields.
      * @return the Field object
-     * @throws IllegalArgumentException if the class or field name is null
+     * @throws IllegalArgumentException if the class is null, the field name is null or if
the field could not be found
      * @throws IllegalAccessException if the field is not made accessible
      */
     public static Object readStaticField(Class<?> cls, String fieldName, boolean forceAccess)
@@ -252,7 +252,7 @@ public class FieldUtils {
      * @param cls  the class to reflect, must not be null
      * @param fieldName  the field name to obtain
      * @return the value of the field
-     * @throws IllegalArgumentException if the class or field name is null
+     * @throws IllegalArgumentException if the class is null, the field name is null or if
the field could not be found
      * @throws IllegalAccessException if the field is not accessible
      */
     public static Object readDeclaredStaticField(Class<?> cls, String fieldName) throws
IllegalAccessException {
@@ -269,7 +269,7 @@ public class FieldUtils {
      *  <code>setAccessible</code> method. <code>False</code> will
only
      *  match public fields.
      * @return the Field object
-     * @throws IllegalArgumentException if the class or field name is null
+     * @throws IllegalArgumentException if the class is null, the field name is null or if
the field could not be found
      * @throws IllegalAccessException if the field is not made accessible
      */
     public static Object readDeclaredStaticField(Class<?> cls, String fieldName, boolean
forceAccess)

Modified: commons/proper/lang/trunk/src/site/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/site/changes/changes.xml?rev=1142555&r1=1142554&r2=1142555&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/site/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/site/changes/changes.xml Mon Jul  4 06:18:26 2011
@@ -22,6 +22,8 @@
   <body>
 
   <release version="3.0" date="Unreleased" description="Backwards incompatible update
of Commons Lang to Java 5">
+    <action type="update" issue="LANG-713">Increase test coverage of FieldUtils read
methods and tweak javadoc</action>
+    <action type="fix" issue="LANG-711">Add includeantruntime=false to javac targets
to quell warnings in ant 1.8.1 and better (and modest performance gain).</action>
     <action type="fix" issue="LANG-710">StringIndexOutOfBoundsException when calling
unescapeHtml4("&amp;#03")</action>
     <action type="fix" issue="LANG-703">StringUtils.join throws NPE when toString returns
null for one of objects in collection</action>
     <action type="add" issue="LANG-697">Add FormattableUtils class</action>

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=1142555&r1=1142554&r2=1142555&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
Mon Jul  4 06:18:26 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.lang3.reflect;
 
+import static org.junit.Assume.*;
+
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -86,6 +88,20 @@ public class FieldUtilsTest extends Test
         assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "b"));
         assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "i"));
         assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "d"));
+        
+        try {
+            FieldUtils.getField(null, "none");
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            FieldUtils.getField(PublicChild.class, null);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testGetFieldForceAccess() {
@@ -112,6 +128,20 @@ public class FieldUtilsTest extends Test
                 .getDeclaringClass());
         assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class,
"d", true)
                 .getDeclaringClass());
+        
+        try {
+            FieldUtils.getField(null, "none", true);
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            FieldUtils.getField(PublicChild.class, null, true);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testGetDeclaredField() {
@@ -134,6 +164,20 @@ public class FieldUtilsTest extends Test
         assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "b"));
         assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "i"));
         assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d"));
+        
+        try {
+            FieldUtils.getDeclaredField(null, "none");
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            FieldUtils.getDeclaredField(PublicChild.class, null);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testGetDeclaredFieldForceAccess() {
@@ -161,15 +205,62 @@ public class FieldUtilsTest extends Test
                 .getDeclaringClass());
         assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class,
"d", true)
                 .getDeclaringClass());
+        
+        try {
+            FieldUtils.getDeclaredField(null, "none", true);
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            FieldUtils.getDeclaredField(PublicChild.class, null, true);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadStaticField() throws Exception {
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class,
"VALUE")));
+        
+        try {
+            FieldUtils.readStaticField(null);
+            fail("null field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            Field nonStaticField = FieldUtils.getField(PublicChild.class, "s");
+            assumeNotNull(nonStaticField);
+            FieldUtils.readStaticField(nonStaticField);
+            fail("non-static field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
     }
 
     public void testReadStaticFieldForceAccess() throws Exception {
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class,
"VALUE")));
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(PublicChild.class,
"VALUE")));
+        
+        try {
+            FieldUtils.readStaticField(null, true);
+            fail("null field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            Field nonStaticField = FieldUtils.getField(PublicChild.class, "s", true);
+            assumeNotNull(nonStaticField);
+            FieldUtils.readStaticField(nonStaticField);
+            fail("non-static field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadNamedStaticField() throws Exception {
@@ -177,6 +268,34 @@ public class FieldUtilsTest extends Test
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(PubliclyShadowedChild.class, "VALUE"));
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(PrivatelyShadowedChild.class,
"VALUE"));
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(PublicChild.class, "VALUE"));
+        
+        try {
+            FieldUtils.readStaticField(null, "none");
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(Foo.class, null);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(Foo.class, "does_not_exist");
+            fail("a field that doesn't exist should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(PublicChild.class, "s");
+            fail("non-static field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadNamedStaticFieldForceAccess() throws Exception {
@@ -184,6 +303,34 @@ public class FieldUtilsTest extends Test
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(PubliclyShadowedChild.class, "VALUE",
true));
         assertEquals(Foo.VALUE, FieldUtils.readStaticField(PrivatelyShadowedChild.class,
"VALUE", true));
         assertEquals("child", FieldUtils.readStaticField(PublicChild.class, "VALUE", true));
+        
+        try {
+            FieldUtils.readStaticField(null, "none", true);
+            fail("null class should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(Foo.class, null, true);
+            fail("null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(Foo.class, "does_not_exist", true);
+            fail("a field that doesn't exist should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readStaticField(PublicChild.class, "s", false);
+            fail("non-static field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadDeclaredNamedStaticField() throws Exception {
@@ -242,6 +389,13 @@ public class FieldUtilsTest extends Test
         assertEquals(D0, FieldUtils.readField(parentD, publicChild));
         assertEquals(D0, FieldUtils.readField(parentD, publiclyShadowedChild));
         assertEquals(D0, FieldUtils.readField(parentD, privatelyShadowedChild));
+        
+        try {
+            FieldUtils.readField((Field)null, publicChild);
+            fail("a null field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadFieldForceAccess() throws Exception {
@@ -265,12 +419,34 @@ public class FieldUtilsTest extends Test
         assertEquals(D0, FieldUtils.readField(parentD, publicChild, true));
         assertEquals(D0, FieldUtils.readField(parentD, publiclyShadowedChild, true));
         assertEquals(D0, FieldUtils.readField(parentD, privatelyShadowedChild, true));
+        
+        try {
+            FieldUtils.readField((Field)null, publicChild, true);
+            fail("a null field should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadNamedField() throws Exception {
         assertEquals("s", FieldUtils.readField(publicChild, "s"));
         assertEquals("ss", FieldUtils.readField(publiclyShadowedChild, "s"));
         assertEquals("s", FieldUtils.readField(privatelyShadowedChild, "s"));
+        
+        try {
+            FieldUtils.readField(publicChild, null);
+            fail("a null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readField((Object)null, "none");
+            fail("a null target should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
         try {
             assertEquals(Boolean.FALSE, FieldUtils.readField(publicChild, "b"));
             fail("expected IllegalArgumentException");
@@ -325,10 +501,38 @@ public class FieldUtilsTest extends Test
         assertEquals(D0, FieldUtils.readField(publicChild, "d", true));
         assertEquals(D1, FieldUtils.readField(publiclyShadowedChild, "d", true));
         assertEquals(D1, FieldUtils.readField(privatelyShadowedChild, "d", true));
+        
+        try {
+            FieldUtils.readField(publicChild, null, true);
+            fail("a null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readField((Object)null, "none", true);
+            fail("a null target should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
     }
 
     public void testReadDeclaredNamedField() throws Exception {
         try {
+            FieldUtils.readDeclaredField(publicChild, null);
+            fail("a null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readDeclaredField((Object)null, "none");
+            fail("a null target should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
             assertEquals("s", FieldUtils.readDeclaredField(publicChild, "s"));
             fail("expected IllegalArgumentException");
         } catch (IllegalArgumentException e) {
@@ -384,6 +588,20 @@ public class FieldUtilsTest extends Test
 
     public void testReadDeclaredNamedFieldForceAccess() throws Exception {
         try {
+            FieldUtils.readDeclaredField(publicChild, null, true);
+            fail("a null field name should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            FieldUtils.readDeclaredField((Object)null, "none", true);
+            fail("a null target should cause an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
             assertEquals("s", FieldUtils.readDeclaredField(publicChild, "s", true));
             fail("expected IllegalArgumentException");
         } catch (IllegalArgumentException e) {



Mime
View raw message