commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1562994 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
Date Thu, 30 Jan 2014 22:00:42 GMT
Author: ggregory
Date: Thu Jan 30 22:00:42 2014
New Revision: 1562994

URL: http://svn.apache.org/r1562994
Log:
[LANG-961] org.apache.commons.lang3.reflect.FieldUtils.removeFinalModifier(Field) does not
clean up after itself.

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=1562994&r1=1562993&r2=1562994&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 Jan 30 22:00:42 2014
@@ -1259,7 +1259,42 @@ public class FieldUtilsTest {
         assertFalse(field.isAccessible());
         assertTrue(Modifier.isFinal(field.getModifiers()));
         FieldUtils.removeFinalModifier(field);
+        // The field is no longer final
         assertFalse(Modifier.isFinal(field.getModifiers()));
         assertFalse(field.isAccessible());
     }
+    
+    @Test
+    public void testRemoveFinalModifierWithAccess() throws Exception {
+        Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
+        assertFalse(field.isAccessible());
+        assertTrue(Modifier.isFinal(field.getModifiers()));
+        FieldUtils.removeFinalModifier(field, true);
+        // The field is no longer final
+        assertFalse(Modifier.isFinal(field.getModifiers()));
+        assertFalse(field.isAccessible());
+    }
+
+    @Test
+    public void testRemoveFinalModifierWithoutAccess() throws Exception {
+        Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
+        assertFalse(field.isAccessible());
+        assertTrue(Modifier.isFinal(field.getModifiers()));
+        FieldUtils.removeFinalModifier(field, false);
+        // The field is STILL final because we did not force access
+        assertTrue(Modifier.isFinal(field.getModifiers()));
+        assertFalse(field.isAccessible());
+    }
+
+    @Test
+    public void testRemoveFinalModifierAccessNotNeeded() throws Exception {
+        Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE");
+        assertFalse(field.isAccessible());
+        assertTrue(Modifier.isFinal(field.getModifiers()));
+        FieldUtils.removeFinalModifier(field, false);
+        // The field is no longer final AND we did not need to force access
+        assertTrue(Modifier.isFinal(field.getModifiers()));
+        assertFalse(field.isAccessible());
+    }
+
 }



Mime
View raw message