You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2008/05/06 00:12:51 UTC
svn commit: r653618 [2/2] - in
/commons/proper/lang/branches/LANG_POST_2_4/src:
java/org/apache/commons/lang/reflect/ test/org/apache/commons/lang/
test/org/apache/commons/lang/reflect/
test/org/apache/commons/lang/reflect/testbed/
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java Mon May 5 15:12:48 2008
@@ -0,0 +1,920 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect;
+
+import java.lang.reflect.Field;
+
+import org.apache.commons.lang.reflect.testbed.Ambig;
+import org.apache.commons.lang.reflect.testbed.Foo;
+import org.apache.commons.lang.reflect.testbed.PrivatelyShadowedChild;
+import org.apache.commons.lang.reflect.testbed.PublicChild;
+import org.apache.commons.lang.reflect.testbed.PubliclyShadowedChild;
+import org.apache.commons.lang.reflect.testbed.StaticContainer;
+import org.apache.commons.lang.reflect.testbed.StaticContainerChild;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests FieldUtils
+ * @author mbenson
+ * @version $Id$
+ */
+public class FieldUtilsTest extends TestCase {
+
+ static final String S = "s";
+ static final String SS = "ss";
+ static final Integer I0 = new Integer(0);
+ static final Integer I1 = new Integer(1);
+ static final Double D0 = new Double(0.0);
+ static final Double D1 = new Double(1.0);
+
+ private PublicChild publicChild;
+ private PubliclyShadowedChild publiclyShadowedChild;
+ private PrivatelyShadowedChild privatelyShadowedChild;
+ private Class parentClass = PublicChild.class.getSuperclass();
+
+ /**
+ * Run the test cases as a suite.
+ * @return the Test
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(FieldUtilsTest.class);
+ suite.setName("FieldUtils Tests");
+ return suite;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ StaticContainer.reset();
+ publicChild = new PublicChild();
+ publiclyShadowedChild = new PubliclyShadowedChild();
+ privatelyShadowedChild = new PrivatelyShadowedChild();
+ }
+
+ public void testGetField() {
+ assertEquals(Foo.class, FieldUtils.getField(PublicChild.class, "VALUE").getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PublicChild.class, "s").getDeclaringClass());
+ assertNull(FieldUtils.getField(PublicChild.class, "b"));
+ assertNull(FieldUtils.getField(PublicChild.class, "i"));
+ assertNull(FieldUtils.getField(PublicChild.class, "d"));
+ assertEquals(Foo.class, FieldUtils.getField(PubliclyShadowedChild.class, "VALUE").getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "s")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "b")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "i")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "d")
+ .getDeclaringClass());
+ assertEquals(Foo.class, FieldUtils.getField(PrivatelyShadowedChild.class, "VALUE").getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PrivatelyShadowedChild.class, "s").getDeclaringClass());
+ assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "b"));
+ assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "i"));
+ assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "d"));
+ }
+
+ public void testGetFieldForceAccess() {
+ assertEquals(PublicChild.class, FieldUtils.getField(PublicChild.class, "VALUE", true).getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PublicChild.class, "s", true).getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PublicChild.class, "b", true).getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PublicChild.class, "i", true).getDeclaringClass());
+ assertEquals(parentClass, FieldUtils.getField(PublicChild.class, "d", true).getDeclaringClass());
+ assertEquals(Foo.class, FieldUtils.getField(PubliclyShadowedChild.class, "VALUE", true).getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "s", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "b", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "i", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getField(PubliclyShadowedChild.class, "d", true)
+ .getDeclaringClass());
+ assertEquals(Foo.class, FieldUtils.getField(PrivatelyShadowedChild.class, "VALUE", true).getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "s", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "b", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "i", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "d", true)
+ .getDeclaringClass());
+ }
+
+ public void testGetDeclaredField() {
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "VALUE"));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "s"));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "b"));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "i"));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "d"));
+ assertNull(FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "VALUE"));
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "s")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "b")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "i")
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "d")
+ .getDeclaringClass());
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "VALUE"));
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "s"));
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "b"));
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "i"));
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d"));
+ }
+
+ public void testGetDeclaredFieldForceAccess() {
+ assertEquals(PublicChild.class, FieldUtils.getDeclaredField(PublicChild.class, "VALUE", true)
+ .getDeclaringClass());
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "s", true));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "b", true));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "i", true));
+ assertNull(FieldUtils.getDeclaredField(PublicChild.class, "d", true));
+ assertNull(FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "VALUE", true));
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "s", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "b", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "i", true)
+ .getDeclaringClass());
+ assertEquals(PubliclyShadowedChild.class, FieldUtils.getDeclaredField(PubliclyShadowedChild.class, "d", true)
+ .getDeclaringClass());
+ assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "VALUE", true));
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "s", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "b", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "i", true)
+ .getDeclaringClass());
+ assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d", true)
+ .getDeclaringClass());
+ }
+
+ public void testReadStaticField() throws Exception {
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE")));
+ }
+
+ 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")));
+ }
+
+ public void testReadNamedStaticField() throws Exception {
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(Foo.class, "VALUE"));
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(PubliclyShadowedChild.class, "VALUE"));
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(PrivatelyShadowedChild.class, "VALUE"));
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(PublicChild.class, "VALUE"));
+ }
+
+ public void testReadNamedStaticFieldForceAccess() throws Exception {
+ assertEquals(Foo.VALUE, FieldUtils.readStaticField(Foo.class, "VALUE", true));
+ 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));
+ }
+
+ public void testReadDeclaredNamedStaticField() throws Exception {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(Foo.class, "VALUE"));
+ try {
+ assertEquals("child", FieldUtils.readDeclaredStaticField(PublicChild.class, "VALUE"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(PubliclyShadowedChild.class, "VALUE"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, "VALUE"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testReadDeclaredNamedStaticFieldForceAccess() throws Exception {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(Foo.class, "VALUE", true));
+ assertEquals("child", FieldUtils.readDeclaredStaticField(PublicChild.class, "VALUE", true));
+ try {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(PubliclyShadowedChild.class, "VALUE", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, "VALUE", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testReadField() throws Exception {
+ Field parentS = FieldUtils.getDeclaredField(parentClass, "s");
+ assertEquals("s", FieldUtils.readField(parentS, publicChild));
+ assertEquals("s", FieldUtils.readField(parentS, publiclyShadowedChild));
+ assertEquals("s", FieldUtils.readField(parentS, privatelyShadowedChild));
+ Field parentB = FieldUtils.getDeclaredField(parentClass, "b", true);
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, publicChild));
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, publiclyShadowedChild));
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, privatelyShadowedChild));
+ Field parentI = FieldUtils.getDeclaredField(parentClass, "i", true);
+ assertEquals(I0, FieldUtils.readField(parentI, publicChild));
+ assertEquals(I0, FieldUtils.readField(parentI, publiclyShadowedChild));
+ assertEquals(I0, FieldUtils.readField(parentI, privatelyShadowedChild));
+ Field parentD = FieldUtils.getDeclaredField(parentClass, "d", true);
+ assertEquals(D0, FieldUtils.readField(parentD, publicChild));
+ assertEquals(D0, FieldUtils.readField(parentD, publiclyShadowedChild));
+ assertEquals(D0, FieldUtils.readField(parentD, privatelyShadowedChild));
+ }
+
+ public void testReadFieldForceAccess() throws Exception {
+ Field parentS = FieldUtils.getDeclaredField(parentClass, "s");
+ parentS.setAccessible(false);
+ assertEquals("s", FieldUtils.readField(parentS, publicChild, true));
+ assertEquals("s", FieldUtils.readField(parentS, publiclyShadowedChild, true));
+ assertEquals("s", FieldUtils.readField(parentS, privatelyShadowedChild, true));
+ Field parentB = FieldUtils.getDeclaredField(parentClass, "b", true);
+ parentB.setAccessible(false);
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, publicChild, true));
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, publiclyShadowedChild, true));
+ assertEquals(Boolean.FALSE, FieldUtils.readField(parentB, privatelyShadowedChild, true));
+ Field parentI = FieldUtils.getDeclaredField(parentClass, "i", true);
+ parentI.setAccessible(false);
+ assertEquals(I0, FieldUtils.readField(parentI, publicChild, true));
+ assertEquals(I0, FieldUtils.readField(parentI, publiclyShadowedChild, true));
+ assertEquals(I0, FieldUtils.readField(parentI, privatelyShadowedChild, true));
+ Field parentD = FieldUtils.getDeclaredField(parentClass, "d", true);
+ parentD.setAccessible(false);
+ assertEquals(D0, FieldUtils.readField(parentD, publicChild, true));
+ assertEquals(D0, FieldUtils.readField(parentD, publiclyShadowedChild, true));
+ assertEquals(D0, FieldUtils.readField(parentD, privatelyShadowedChild, true));
+ }
+
+ public void testReadNamedField() throws Exception {
+ assertEquals("s", FieldUtils.readField(publicChild, "s"));
+ assertEquals("ss", FieldUtils.readField(publiclyShadowedChild, "s"));
+ assertEquals("s", FieldUtils.readField(privatelyShadowedChild, "s"));
+ try {
+ assertEquals(Boolean.FALSE, FieldUtils.readField(publicChild, "b"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(Boolean.TRUE, FieldUtils.readField(publiclyShadowedChild, "b"));
+ try {
+ assertEquals(Boolean.FALSE, FieldUtils.readField(privatelyShadowedChild, "b"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(I0, FieldUtils.readField(publicChild, "i"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(I1, FieldUtils.readField(publiclyShadowedChild, "i"));
+ try {
+ assertEquals(I0, FieldUtils.readField(privatelyShadowedChild, "i"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(D0, FieldUtils.readField(publicChild, "d"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(D1, FieldUtils.readField(publiclyShadowedChild, "d"));
+ try {
+ assertEquals(D0, FieldUtils.readField(privatelyShadowedChild, "d"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testReadNamedFieldForceAccess() throws Exception {
+ assertEquals("s", FieldUtils.readField(publicChild, "s", true));
+ assertEquals("ss", FieldUtils.readField(publiclyShadowedChild, "s", true));
+ assertEquals("ss", FieldUtils.readField(privatelyShadowedChild, "s", true));
+ assertEquals(Boolean.FALSE, FieldUtils.readField(publicChild, "b", true));
+ assertEquals(Boolean.TRUE, FieldUtils.readField(publiclyShadowedChild, "b", true));
+ assertEquals(Boolean.TRUE, FieldUtils.readField(privatelyShadowedChild, "b", true));
+ assertEquals(I0, FieldUtils.readField(publicChild, "i", true));
+ assertEquals(I1, FieldUtils.readField(publiclyShadowedChild, "i", true));
+ assertEquals(I1, FieldUtils.readField(privatelyShadowedChild, "i", true));
+ assertEquals(D0, FieldUtils.readField(publicChild, "d", true));
+ assertEquals(D1, FieldUtils.readField(publiclyShadowedChild, "d", true));
+ assertEquals(D1, FieldUtils.readField(privatelyShadowedChild, "d", true));
+ }
+
+ public void testReadDeclaredNamedField() throws Exception {
+ try {
+ assertEquals("s", FieldUtils.readDeclaredField(publicChild, "s"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s"));
+ try {
+ assertEquals("s", FieldUtils.readDeclaredField(privatelyShadowedChild, "s"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publicChild, "b"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(Boolean.TRUE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b"));
+ try {
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(privatelyShadowedChild, "b"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(I0, FieldUtils.readDeclaredField(publicChild, "i"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(I1, FieldUtils.readDeclaredField(publiclyShadowedChild, "i"));
+ try {
+ assertEquals(I0, FieldUtils.readDeclaredField(privatelyShadowedChild, "i"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ assertEquals(D0, FieldUtils.readDeclaredField(publicChild, "d"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(D1, FieldUtils.readDeclaredField(publiclyShadowedChild, "d"));
+ try {
+ assertEquals(D0, FieldUtils.readDeclaredField(privatelyShadowedChild, "d"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testReadDeclaredNamedFieldForceAccess() throws Exception {
+ try {
+ assertEquals("s", FieldUtils.readDeclaredField(publicChild, "s", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s", true));
+ assertEquals("ss", FieldUtils.readDeclaredField(privatelyShadowedChild, "s", true));
+ try {
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publicChild, "b", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(Boolean.TRUE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b", true));
+ assertEquals(Boolean.TRUE, FieldUtils.readDeclaredField(privatelyShadowedChild, "b", true));
+ try {
+ assertEquals(I0, FieldUtils.readDeclaredField(publicChild, "i", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(I1, FieldUtils.readDeclaredField(publiclyShadowedChild, "i", true));
+ assertEquals(I1, FieldUtils.readDeclaredField(privatelyShadowedChild, "i", true));
+ try {
+ assertEquals(D0, FieldUtils.readDeclaredField(publicChild, "d", true));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ assertEquals(D1, FieldUtils.readDeclaredField(publiclyShadowedChild, "d", true));
+ assertEquals(D1, FieldUtils.readDeclaredField(privatelyShadowedChild, "d", true));
+ }
+
+ public void testWriteStaticField() throws Exception {
+ Field field = StaticContainer.class.getDeclaredField("mutablePublic");
+ FieldUtils.writeStaticField(field, "new");
+ assertEquals("new", StaticContainer.mutablePublic);
+ field = StaticContainer.class.getDeclaredField("mutableProtected");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("mutablePackage");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("mutablePrivate");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PUBLIC");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PROTECTED");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE");
+ try {
+ FieldUtils.writeStaticField(field, "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ }
+
+ public void testWriteStaticFieldForceAccess() throws Exception {
+ Field field = StaticContainer.class.getDeclaredField("mutablePublic");
+ FieldUtils.writeStaticField(field, "new", true);
+ assertEquals("new", StaticContainer.mutablePublic);
+ field = StaticContainer.class.getDeclaredField("mutableProtected");
+ FieldUtils.writeStaticField(field, "new", true);
+ assertEquals("new", StaticContainer.getMutableProtected());
+ field = StaticContainer.class.getDeclaredField("mutablePackage");
+ FieldUtils.writeStaticField(field, "new", true);
+ assertEquals("new", StaticContainer.getMutablePackage());
+ field = StaticContainer.class.getDeclaredField("mutablePrivate");
+ FieldUtils.writeStaticField(field, "new", true);
+ assertEquals("new", StaticContainer.getMutablePrivate());
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PUBLIC");
+ try {
+ FieldUtils.writeStaticField(field, "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PROTECTED");
+ try {
+ FieldUtils.writeStaticField(field, "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE");
+ try {
+ FieldUtils.writeStaticField(field, "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE");
+ try {
+ FieldUtils.writeStaticField(field, "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ }
+
+ public void testWriteNamedStaticField() throws Exception {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePublic", "new");
+ assertEquals("new", StaticContainer.mutablePublic);
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutableProtected", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePackage", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePrivate", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PUBLIC", "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PROTECTED", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PACKAGE", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PRIVATE", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testWriteNamedStaticFieldForceAccess() throws Exception {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePublic", "new", true);
+ assertEquals("new", StaticContainer.mutablePublic);
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutableProtected", "new", true);
+ assertEquals("new", StaticContainer.getMutableProtected());
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePackage", "new", true);
+ assertEquals("new", StaticContainer.getMutablePackage());
+ FieldUtils.writeStaticField(StaticContainerChild.class, "mutablePrivate", "new", true);
+ assertEquals("new", StaticContainer.getMutablePrivate());
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PUBLIC", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PROTECTED", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PACKAGE", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PRIVATE", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ }
+
+ public void testWriteDeclaredNamedStaticField() throws Exception {
+ FieldUtils.writeStaticField(StaticContainer.class, "mutablePublic", "new");
+ assertEquals("new", StaticContainer.mutablePublic);
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutableProtected", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePackage", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePrivate", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PUBLIC", "new");
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PROTECTED", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PACKAGE", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testWriteDeclaredNamedStaticFieldForceAccess() throws Exception {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePublic", "new", true);
+ assertEquals("new", StaticContainer.mutablePublic);
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutableProtected", "new", true);
+ assertEquals("new", StaticContainer.getMutableProtected());
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePackage", "new", true);
+ assertEquals("new", StaticContainer.getMutablePackage());
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePrivate", "new", true);
+ assertEquals("new", StaticContainer.getMutablePrivate());
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PUBLIC", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PROTECTED", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PACKAGE", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new", true);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ }
+
+ public void testWriteField() throws Exception {
+ Field field = parentClass.getDeclaredField("s");
+ FieldUtils.writeField(field, publicChild, "S");
+ assertEquals("S", field.get(publicChild));
+ field = parentClass.getDeclaredField("b");
+ try {
+ FieldUtils.writeField(field, publicChild, Boolean.TRUE);
+ fail("Expected IllegalAccessException");
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = parentClass.getDeclaredField("i");
+ try {
+ FieldUtils.writeField(field, publicChild, new Integer(Integer.MAX_VALUE));
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ field = parentClass.getDeclaredField("d");
+ try {
+ FieldUtils.writeField(field, publicChild, new Double(Double.MAX_VALUE));
+ } catch (IllegalAccessException e) {
+ // pass
+ }
+ }
+
+ public void testWriteFieldForceAccess() throws Exception {
+ Field field = parentClass.getDeclaredField("s");
+ FieldUtils.writeField(field, publicChild, "S", true);
+ assertEquals("S", field.get(publicChild));
+ field = parentClass.getDeclaredField("b");
+ FieldUtils.writeField(field, publicChild, Boolean.TRUE, true);
+ assertEquals(Boolean.TRUE, field.get(publicChild));
+ field = parentClass.getDeclaredField("i");
+ FieldUtils.writeField(field, publicChild, new Integer(Integer.MAX_VALUE), true);
+ assertEquals(new Integer(Integer.MAX_VALUE), field.get(publicChild));
+ field = parentClass.getDeclaredField("d");
+ FieldUtils.writeField(field, publicChild, new Double(Double.MAX_VALUE), true);
+ assertEquals(new Double(Double.MAX_VALUE), field.get(publicChild));
+ }
+
+ public void testWriteNamedField() throws Exception {
+ FieldUtils.writeField(publicChild, "s", "S");
+ assertEquals("S", FieldUtils.readField(publicChild, "s"));
+ try {
+ FieldUtils.writeField(publicChild, "b", Boolean.TRUE);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeField(publicChild, "i", new Integer(1));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeField(publicChild, "d", new Double(1.0));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+
+ FieldUtils.writeField(publiclyShadowedChild, "s", "S");
+ assertEquals("S", FieldUtils.readField(publiclyShadowedChild, "s"));
+ FieldUtils.writeField(publiclyShadowedChild, "b", Boolean.FALSE);
+ assertEquals(Boolean.FALSE, FieldUtils.readField(publiclyShadowedChild, "b"));
+ FieldUtils.writeField(publiclyShadowedChild, "i", new Integer(0));
+ assertEquals(new Integer(0), FieldUtils.readField(publiclyShadowedChild, "i"));
+ FieldUtils.writeField(publiclyShadowedChild, "d", new Double(0.0));
+ assertEquals(new Double(0.0), FieldUtils.readField(publiclyShadowedChild, "d"));
+
+ FieldUtils.writeField(privatelyShadowedChild, "s", "S");
+ assertEquals("S", FieldUtils.readField(privatelyShadowedChild, "s"));
+ try {
+ FieldUtils.writeField(privatelyShadowedChild, "b", Boolean.TRUE);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeField(privatelyShadowedChild, "i", new Integer(1));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeField(privatelyShadowedChild, "d", new Double(1.0));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testWriteNamedFieldForceAccess() throws Exception {
+ FieldUtils.writeField(publicChild, "s", "S", true);
+ assertEquals("S", FieldUtils.readField(publicChild, "s", true));
+ FieldUtils.writeField(publicChild, "b", Boolean.TRUE, true);
+ assertEquals(Boolean.TRUE, FieldUtils.readField(publicChild, "b", true));
+ FieldUtils.writeField(publicChild, "i", new Integer(1), true);
+ assertEquals(new Integer(1), FieldUtils.readField(publicChild, "i", true));
+ FieldUtils.writeField(publicChild, "d", new Double(1.0), true);
+ assertEquals(new Double(1.0), FieldUtils.readField(publicChild, "d", true));
+
+ FieldUtils.writeField(publiclyShadowedChild, "s", "S", true);
+ assertEquals("S", FieldUtils.readField(publiclyShadowedChild, "s", true));
+ FieldUtils.writeField(publiclyShadowedChild, "b", Boolean.FALSE, true);
+ assertEquals(Boolean.FALSE, FieldUtils.readField(publiclyShadowedChild, "b", true));
+ FieldUtils.writeField(publiclyShadowedChild, "i", new Integer(0), true);
+ assertEquals(new Integer(0), FieldUtils.readField(publiclyShadowedChild, "i", true));
+ FieldUtils.writeField(publiclyShadowedChild, "d", new Double(0.0), true);
+ assertEquals(new Double(0.0), FieldUtils.readField(publiclyShadowedChild, "d", true));
+
+ FieldUtils.writeField(privatelyShadowedChild, "s", "S", true);
+ assertEquals("S", FieldUtils.readField(privatelyShadowedChild, "s", true));
+ FieldUtils.writeField(privatelyShadowedChild, "b", Boolean.FALSE, true);
+ assertEquals(Boolean.FALSE, FieldUtils.readField(privatelyShadowedChild, "b", true));
+ FieldUtils.writeField(privatelyShadowedChild, "i", new Integer(0), true);
+ assertEquals(new Integer(0), FieldUtils.readField(privatelyShadowedChild, "i", true));
+ FieldUtils.writeField(privatelyShadowedChild, "d", new Double(0.0), true);
+ assertEquals(new Double(0.0), FieldUtils.readField(privatelyShadowedChild, "d", true));
+ }
+
+ public void testWriteDeclaredNamedField() throws Exception {
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "s", "S");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "b", Boolean.TRUE);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "i", new Integer(1));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "d", new Double(1.0));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "s", "S");
+ assertEquals("S", FieldUtils.readDeclaredField(publiclyShadowedChild, "s"));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "b", Boolean.FALSE);
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b"));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "i", new Integer(0));
+ assertEquals(new Integer(0), FieldUtils.readDeclaredField(publiclyShadowedChild, "i"));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "d", new Double(0.0));
+ assertEquals(new Double(0.0), FieldUtils.readDeclaredField(publiclyShadowedChild, "d"));
+
+ try {
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "s", "S");
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "b", Boolean.TRUE);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "i", new Integer(1));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "d", new Double(1.0));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testWriteDeclaredNamedFieldForceAccess() throws Exception {
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "s", "S", true);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "b", Boolean.TRUE, true);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "i", new Integer(1), true);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ try {
+ FieldUtils.writeDeclaredField(publicChild, "d", new Double(1.0), true);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "s", "S", true);
+ assertEquals("S", FieldUtils.readDeclaredField(publiclyShadowedChild, "s", true));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "b", Boolean.FALSE, true);
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b", true));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "i", new Integer(0), true);
+ assertEquals(new Integer(0), FieldUtils.readDeclaredField(publiclyShadowedChild, "i", true));
+ FieldUtils.writeDeclaredField(publiclyShadowedChild, "d", new Double(0.0), true);
+ assertEquals(new Double(0.0), FieldUtils.readDeclaredField(publiclyShadowedChild, "d", true));
+
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "s", "S", true);
+ assertEquals("S", FieldUtils.readDeclaredField(privatelyShadowedChild, "s", true));
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "b", Boolean.FALSE, true);
+ assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(privatelyShadowedChild, "b", true));
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "i", new Integer(0), true);
+ assertEquals(new Integer(0), FieldUtils.readDeclaredField(privatelyShadowedChild, "i", true));
+ FieldUtils.writeDeclaredField(privatelyShadowedChild, "d", new Double(0.0), true);
+ assertEquals(new Double(0.0), FieldUtils.readDeclaredField(privatelyShadowedChild, "d", true));
+ }
+
+ public void testAmbig() {
+ try {
+ FieldUtils.getField(Ambig.class, "VALUE");
+ fail("should have failed on interface field ambiguity");
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+}
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/FieldUtilsTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java Mon May 5 15:12:48 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Test suite for the reflect package.
+ *
+ * @author Matt Benson
+ * @version $Id$
+ */
+public class ReflectTestSuite extends TestCase {
+
+ /**
+ * Construct a new instance.
+ */
+ public ReflectTestSuite(String name) {
+ super(name);
+ }
+
+ /**
+ * Command-line interface.
+ */
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ /**
+ * Get the suite of tests
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.setName("Commons-Lang-Reflect Tests");
+ suite.addTest(ConstructorUtilsTest.suite());
+ suite.addTest(FieldUtilsTest.suite());
+ suite.addTest(MethodUtilsTest.suite());
+ return suite;
+ }
+
+}
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java Mon May 5 15:12:48 2008
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class Ambig implements Foo, Bar {
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Ambig.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java Mon May 5 15:12:48 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public interface Bar {
+ public static final String VALUE = "bar";
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Bar.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java Mon May 5 15:12:48 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public interface Foo {
+ public static final String VALUE = "foo";
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Foo.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java Mon May 5 15:12:48 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+class Parent implements Foo {
+ public String s = "s";
+ protected boolean b = false;
+ int i = 0;
+ private double d = 0.0;
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/Parent.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java Mon May 5 15:12:48 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class PrivatelyShadowedChild extends Parent {
+ private String s = "ss";
+ private boolean b = true;
+ private int i = 1;
+ private double d = 1.0;
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PrivatelyShadowedChild.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java Mon May 5 15:12:48 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class PublicChild extends Parent {
+ static final String VALUE = "child";
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PublicChild.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java Mon May 5 15:12:48 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class PubliclyShadowedChild extends Parent {
+ public String s = "ss";
+ public boolean b = true;
+ public int i = 1;
+ public double d = 1.0;
+}
\ No newline at end of file
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/PubliclyShadowedChild.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java Mon May 5 15:12:48 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class StaticContainer {
+ public static final Object IMMUTABLE_PUBLIC = "public";
+ protected static final Object IMMUTABLE_PROTECTED = "protected";
+ static final Object IMMUTABLE_PACKAGE = "";
+ private static final Object IMMUTABLE_PRIVATE = "private";
+
+ public static Object mutablePublic;
+ protected static Object mutableProtected;
+ static Object mutablePackage;
+ private static Object mutablePrivate;
+
+ public static void reset() {
+ mutablePublic = null;
+ mutableProtected = null;
+ mutablePackage = null;
+ mutablePrivate = null;
+ }
+
+ public static Object getMutableProtected() {
+ return mutableProtected;
+ }
+
+ public static Object getMutablePackage() {
+ return mutablePackage;
+ }
+
+ public static Object getMutablePrivate() {
+ return mutablePrivate;
+ }
+}
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainer.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java?rev=653618&view=auto
==============================================================================
--- commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java (added)
+++ commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java Mon May 5 15:12:48 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.reflect.testbed;
+
+/**
+ * @author mbenson
+ * @version $Id$
+ */
+public class StaticContainerChild extends StaticContainer {
+
+}
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/lang/branches/LANG_POST_2_4/src/test/org/apache/commons/lang/reflect/testbed/StaticContainerChild.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 5 15:12:48 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL