diff --git a/build.xml b/build.xml index a5067d8b5..1df9a4128 100644 --- a/build.xml +++ b/build.xml @@ -3,7 +3,7 @@ @@ -153,7 +153,15 @@ - @@ -203,4 +211,12 @@ + + + + + + + diff --git a/src/test/org/apache/commons/lang/reflect/AbstractChild.java b/src/test/org/apache/commons/lang/reflect/AbstractChild.java new file mode 100644 index 000000000..ec9d78d3d --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/AbstractChild.java @@ -0,0 +1,74 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.lang.reflect; + +public class AbstractChild implements Child { + + private String name; + + protected void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + +} diff --git a/src/test/org/apache/commons/lang/reflect/AbstractParent.java b/src/test/org/apache/commons/lang/reflect/AbstractParent.java new file mode 100644 index 000000000..bdd560b12 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/AbstractParent.java @@ -0,0 +1,94 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.lang.reflect; + +public abstract class AbstractParent { + + private Child child; + + public Child getChild() + { + return child; + } + + /** + * Method which matches signature but which has wrong parameters + */ + public String testAddChild(String badParameter) { + return null; + } + + /** + * Method which matches signature but which has wrong parameters + */ + public String testAddChild2(String ignore, String badParameter) { + return null; + } + + public String testAddChild(Child child) { + this.child = child; + return child.getName(); + } + + + public String testAddChild2(String ignore, Child child) { + this.child = child; + return child.getName(); + } + +} diff --git a/src/test/org/apache/commons/lang/reflect/AlphaBean.java b/src/test/org/apache/commons/lang/reflect/AlphaBean.java new file mode 100644 index 000000000..1e0daa035 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/AlphaBean.java @@ -0,0 +1,80 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.lang.reflect; + +public class AlphaBean extends AbstractParent implements Child { + + private String name; + + public AlphaBean(String name) { + setName(name); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Used for testing that correct exception is thrown. + */ + public void bogus(String badParameter){} +} diff --git a/src/test/org/apache/commons/lang/reflect/BetaBean.java b/src/test/org/apache/commons/lang/reflect/BetaBean.java new file mode 100644 index 000000000..5305305ea --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/BetaBean.java @@ -0,0 +1,65 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.lang.reflect; + +public class BetaBean extends AbstractChild { + + public BetaBean(String name) { + setName(name); + } +} diff --git a/src/test/org/apache/commons/lang/reflect/Child.java b/src/test/org/apache/commons/lang/reflect/Child.java new file mode 100644 index 000000000..f7a7dd547 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/Child.java @@ -0,0 +1,64 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect; + +public interface Child { + + public String getName(); +} diff --git a/src/test/org/apache/commons/lang/reflect/MethodUtilsTestCase.java b/src/test/org/apache/commons/lang/reflect/MethodUtilsTestCase.java new file mode 100644 index 000000000..078b7bc2d --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/MethodUtilsTestCase.java @@ -0,0 +1,586 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect; + + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.apache.commons.lang.reflect.priv.PrivateBeanFactory; +import org.apache.commons.lang.reflect.priv.PublicSubBean; + +import junit.framework.TestCase; +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + *

Test case for MethodUtils

+ * + */ +public class MethodUtilsTestCase extends TestCase { + + // ---------------------------------------------------- Instance Variables + + protected PrivateBeanFactory privateBeanFactory; + + // ---------------------------------------------------------- Constructors + + /** + * Construct a new instance of this test case. + * + * @param name Name of the test case + */ + public MethodUtilsTestCase(String name) { + super(name); + } + + + // -------------------------------------------------- Overall Test Methods + + + /** + * Set up instance variables required by this test case. + */ + public void setUp() { + privateBeanFactory = new PrivateBeanFactory(); + } + + + /** + * Return the tests included in this test suite. + */ + public static Test suite() { + return (new TestSuite(MethodUtilsTestCase.class)); + } + + /** + * Tear down instance variables required by this test case. + */ + public void tearDown() { + privateBeanFactory = null; + } + + + // ------------------------------------------------ Individual Test Methods + + /** + *

Test getAccessibleMethod. + */ + public void testGetAccessibleMethod() { + // test MethodUtils.getAccessibleMethod + // we'll make things easier by using the convenience methods + + // easy bit first - find a public method + // METHOD ONE + Method method = MethodUtils.getAccessibleMethod + (TestBean.class, "setStringProperty", String.class); + + // check that we've found one that matches + assertNotNull(method); + assertEquals("method ONE is named correctly", + "setStringProperty", method.getName()); + assertTrue("Method ONE is public", + Modifier.isPublic(method.getModifiers())); + + // trickier this one - find a method in a direct interface + // METHOD TWO + method = MethodUtils.getAccessibleMethod + (privateBeanFactory.create().getClass(), + "methodBar", + String.class); + + // check that we've found one that matches + assertNotNull(method); + assertEquals("Method TWO is named correctly", + "methodBar", method.getName()); + assertTrue("Method TWO is public", + Modifier.isPublic(method.getModifiers())); + + // trickier this one - find a method in a indirect interface + // METHOD THREE + method = MethodUtils.getAccessibleMethod + (privateBeanFactory.createSubclass().getClass(), + "methodBaz", + String.class); + + // check that we've found one that matches + assertNotNull(method); + assertEquals("Method THREE is named correctly", + "methodBaz", method.getName()); + assertTrue("Method THREE is public", + Modifier.isPublic(method.getModifiers())); + + } + + + /** + *

Test invokeExactMethod. + */ + public void testInvokeExactMethod() { + // test MethodUtils.invokeExactMethod + // easy bit first - invoke a public method + // METHOD ONE + try { + + TestBean bean = new TestBean(); + Object ret = MethodUtils.invokeExactMethod(bean, "setStringProperty", "TEST"); + // check that the return's right and that the properties been set + assertNull(ret); + assertEquals("Method ONE was invoked", "TEST", bean.getStringProperty()); + + } catch (Throwable t) { + // ONE + fail("Exception in method ONE prevented invokation: " + t.toString()); + } + + // trickier this one - find a method in a direct interface + // METHOD TWO FAILURE + try { + + Object ret = MethodUtils.invokeExactMethod( + privateBeanFactory.create(), + "methodBar", + "ANOTHER TEST"); + + // check that we've found one that matches + assertEquals("Method TWO was invoked correctly", "ANOTHER TEST", ret); + + } catch (Throwable t) { + // METHOD TWO FAILURE + fail("Exception in method TWO prevented invokation: " + t.toString()); + } + + + // trickier this one - find a method in a indirect interface + // METHOD THREE + try { + + Object ret = MethodUtils.invokeExactMethod( + privateBeanFactory.createSubclass(), + "methodBaz", + "YET ANOTHER TEST"); + + + // check that we've found one that matches + assertEquals("Method TWO was invoked correctly", "YET ANOTHER TEST", ret); + + + } catch (Throwable t) { + // METHOD THREE FAILURE + fail("Exception in method THREE prevented invokation: " + t.toString()); + + } + } + + /** + *

Test invokeMethod. + */ + public void testInvokeMethod() throws Exception { + // i'm going to test that the actual calls work first and then try them via reflection + + AbstractParent parent = new AlphaBean("parent"); + + // try testAddChild through abstract superclass + BetaBean childOne = new BetaBean("ChildOne"); + + assertEquals("Oh no! Badly coded test case! (1)", "ChildOne", parent.testAddChild(childOne)); + + // let's try MethodUtils version + assertEquals( + "Cannot invoke through abstract class (1)", + "ChildOne", + MethodUtils.invokeMethod(parent, "testAddChild", childOne)); + + + // try adding through interface + AlphaBean childTwo = new AlphaBean("ChildTwo"); + + assertEquals("Oh no! Badly coded test case! (2)", "ChildTwo", parent.testAddChild(childTwo)); + + // let's try MethodUtils version + assertEquals( + "Cannot invoke through interface (1)", + "ChildTwo", + MethodUtils.invokeMethod(parent, "testAddChild", childTwo)); + + + Object[] params = new Object[2]; + + assertEquals("Oh no! Badly coded test case! (3)", "ChildOne", parent.testAddChild2("parameter", childOne)); + + + // let's try MethodUtils version + params[0] = "parameter"; + params[1] = childOne; + + assertEquals( + "Cannot invoke through abstract class (1)", + "ChildOne", + MethodUtils.invokeMethod(parent, "testAddChild2", params)); + + assertEquals("Oh no! Badly coded test case! (4)", "ChildTwo", parent.testAddChild2("parameter", childTwo)); + + // let's try MethodUtils version + params[0] = "parameter"; + params[1] = childTwo; + + assertEquals( + "Cannot invoke through abstract class (1)", + "ChildTwo", + MethodUtils.invokeMethod(parent, "testAddChild2", params)); + + // test that exception is correctly thrown when a method cannot be found with matching params + try { + // the next line + parent = new AlphaBean("parent"); + childOne = new BetaBean("ChildOne"); + MethodUtils.invokeMethod(parent, "bogus", childOne); + // should get here! + fail("No exception thrown when no appropriate method exists"); + + } catch (NoSuchMethodException e) { + // this is what we're expecting! + } + + MethodUtils.invokeMethod(parent, "getName", null); + MethodUtils.invokeMethod(parent, "getName", null, null); + MethodUtils.invokeExactMethod(parent, "getName", null); + MethodUtils.invokeExactMethod(parent, "getName", null, null); + } + + + /** + *

Test invokeMethod with a primitive. + */ + public void testInvokeMethodWithPrimitives() throws Exception { + // first test that the bean works + PrimitiveBean bean = new PrimitiveBean(); + bean.setFloat(20.0f); + bean.setLong(10l); + bean.setBoolean(true); + bean.setInt(12); + bean.setDouble(25.5d); + + assertEquals("Bug in PrimitiveBean (1)", 20.0f, bean.getFloat(), 0.01f); + assertEquals("Bug in PrimitiveBean (2)", 10, bean.getLong()); + assertEquals("Bug in PrimitiveBean (3)", true, bean.getBoolean()); + assertEquals("Bug in PrimitiveBean (4)", 12, bean.getInt()); + assertEquals("Bug in PrimitiveBean (5)", 25.5d, bean.getDouble(), 0.01f); + + bean = new PrimitiveBean(); + MethodUtils.invokeMethod(bean, "setBoolean", new Boolean(true)); + assertEquals("Call boolean property using invokeMethod", true, bean.getBoolean()); + + bean = new PrimitiveBean(); + MethodUtils.invokeMethod(bean, "setFloat", new Float(20.0f)); + assertEquals("Call float property using invokeMethod", 20.0f, bean.getFloat(), 0.01f); + + bean = new PrimitiveBean(); + MethodUtils.invokeMethod(bean, "setLong", new Long(10)); + assertEquals("Call float property using invokeMethod", 10, bean.getLong()); + + bean = new PrimitiveBean(); + MethodUtils.invokeMethod(bean, "setInt", new Integer(12)); + assertEquals("Set float property using invokeMethod", 12, bean.getInt()); + + bean = new PrimitiveBean(); + MethodUtils.invokeMethod(bean, "setDouble", new Double(25.5d)); + assertEquals("Set float property using invokeMethod", 25.5d, bean.getDouble(), 0.01d); + } + + + /** + * Simple tests for accessing static methods via invokeMethod(). + */ + public void testSimpleStatic1() { + + TestBean bean = new TestBean(); + Object value = null; + int current = TestBean.currentCounter(); + + try { + + // Return initial value of the counter + value = MethodUtils.invokeMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via no-arguments version + MethodUtils.invokeMethod + (bean, "incrementCounter", new Object[0], new Class[0]); + + // Validate updated value + current++; + value = MethodUtils.invokeMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via specified-argument version + MethodUtils.invokeMethod + (bean, "incrementCounter", + new Object[] { new Integer(5) }, + new Class[] { Integer.TYPE }); + + // Validate updated value + current += 5; + value = MethodUtils.invokeMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + } catch (Exception e) { + fail("Threw exception" + e); + } + + } + + + /** + * Simple tests for accessing static methods via invokeExactMethod(). + */ + public void testSimpleStatic2() { + + TestBean bean = new TestBean(); + Object value = null; + int current = TestBean.currentCounter(); + + try { + + // Return initial value of the counter + value = MethodUtils.invokeExactMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via no-arguments version + MethodUtils.invokeExactMethod + (bean, "incrementCounter", new Object[0], new Class[0]); + + // Validate updated value + current++; + value = MethodUtils.invokeExactMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via specified-argument version + MethodUtils.invokeExactMethod + (bean, "incrementCounter", + new Object[] { new Integer(5) }, + new Class[] { Integer.TYPE }); + + // Validate updated value + current += 5; + value = MethodUtils.invokeExactMethod + (bean, "currentCounter", new Object[0], new Class[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + + } catch (Exception e) { + fail("Threw exception" + e); + } + + } + + + /** + * Simple tests for accessing static methods via getAccessibleMethod() + */ + public void testSimpleStatic3() { + + Object value = null; + int current = TestBean.currentCounter(); + + try { + + // Acquire the methods we need + Method currentCounterMethod = MethodUtils.getAccessibleMethod + (TestBean.class, "currentCounter", + new Class[0]); + assertNotNull("currentCounterMethod exists", + currentCounterMethod); + assertEquals("currentCounterMethod name", + "currentCounter", + currentCounterMethod.getName()); + assertEquals("currentCounterMethod args", + 0, + currentCounterMethod.getParameterTypes().length); + assertTrue("currentCounterMethod public", + Modifier.isPublic(currentCounterMethod.getModifiers())); + assertTrue("currentCounterMethod static", + Modifier.isStatic(currentCounterMethod.getModifiers())); + Method incrementCounterMethod1 = MethodUtils.getAccessibleMethod + (TestBean.class, "incrementCounter", + new Class[0]); + assertNotNull("incrementCounterMethod1 exists", + incrementCounterMethod1); + assertEquals("incrementCounterMethod1 name", + "incrementCounter", + incrementCounterMethod1.getName()); + assertEquals("incrementCounterMethod1 args", + 0, + incrementCounterMethod1.getParameterTypes().length); + assertTrue("incrementCounterMethod1 public", + Modifier.isPublic(incrementCounterMethod1.getModifiers())); + assertTrue("incrementCounterMethod1 static", + Modifier.isStatic(incrementCounterMethod1.getModifiers())); + Method incrementCounterMethod2 = MethodUtils.getAccessibleMethod + (TestBean.class, "incrementCounter", + new Class[] { Integer.TYPE }); + assertNotNull("incrementCounterMethod2 exists", + incrementCounterMethod2); + assertEquals("incrementCounterMethod2 name", + "incrementCounter", + incrementCounterMethod2.getName()); + assertEquals("incrementCounterMethod2 args", + 1, + incrementCounterMethod2.getParameterTypes().length); + assertTrue("incrementCounterMethod2 public", + Modifier.isPublic(incrementCounterMethod2.getModifiers())); + assertTrue("incrementCounterMethod2 static", + Modifier.isStatic(incrementCounterMethod2.getModifiers())); + + // Return initial value of the counter + value = currentCounterMethod.invoke(null, new Object[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via no-arguments version + incrementCounterMethod1.invoke(null, new Object[0]); + + // Validate updated value + current++; + value = currentCounterMethod.invoke(null, new Object[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + // Increment via specified-argument version + incrementCounterMethod2.invoke(null, + new Object[] { new Integer(5) }); + + // Validate updated value + current += 5; + value = currentCounterMethod.invoke(null, new Object[0]); + assertNotNull("currentCounter exists", value); + assertTrue("currentCounter type", + value instanceof Integer); + assertEquals("currentCounter value", + current, + ((Integer) value).intValue()); + + } catch (Exception e) { + fail("Threw exception" + e); + } + + } + + public void testPublicSub() throws Exception { + // make sure that bean does what it should + PublicSubBean bean = new PublicSubBean(); + assertEquals("Start value (foo)", bean.getFoo(), "This is foo"); + assertEquals("Start value (bar)", bean.getBar(), "This is bar"); + bean.setFoo("new foo"); + bean.setBar("new bar"); + assertEquals("Set value (foo)", bean.getFoo(), "new foo"); + assertEquals("Set value (bar)", bean.getBar(), "new bar"); + + // see if we can access public methods in a default access superclass + // from a public access subclass instance + MethodUtils.invokeMethod(bean, "setFoo", "alpha"); + assertEquals("Set value (foo:2)", bean.getFoo(), "alpha"); + MethodUtils.invokeMethod(bean, "setBar", "beta"); + assertEquals("Set value (bar:2)", bean.getFoo(), "alpha"); + } +} diff --git a/src/test/org/apache/commons/lang/reflect/PrimitiveBean.java b/src/test/org/apache/commons/lang/reflect/PrimitiveBean.java new file mode 100644 index 000000000..2fb3d9ca5 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/PrimitiveBean.java @@ -0,0 +1,110 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.lang.reflect; + +/** + * Bean that has primitive properties + */ +public class PrimitiveBean { + + private float _float; + private double _double; + private boolean _boolean; + private long _long; + private int _int; + + public float getFloat() { + return _float; + } + + public void setFloat(float _float) { + this._float = _float; + } + + public double getDouble() { + return _double; + } + + public void setDouble(double _double) { + this._double = _double; + } + + public boolean getBoolean() { + return _boolean; + } + + public void setBoolean(boolean _boolean) { + this._boolean = _boolean; + } + + public long getLong() { + return _long; + } + + public void setLong(long _long) { + this._long = _long; + } + + public int getInt() { + return _int; + } + + public void setInt(int _int) { + this._int = _int; + } +} diff --git a/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java b/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java new file mode 100644 index 000000000..9656fb012 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/ReflectTestSuite.java @@ -0,0 +1,92 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +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 packages. + * + * @author Stephen Colebourne (of original copied from) + * @author Robert Burrell Donkin + * @version $Id: ReflectTestSuite.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + */ +public class ReflectTestSuite extends TestCase { + + /** + * Construct a new instance. + */ + public ReflectTestSuite(String name) { + super(name); + } + + /** + * Executor-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.addTest(MethodUtilsTestCase.suite()); + return suite; + } +} diff --git a/src/test/org/apache/commons/lang/reflect/TestBean.java b/src/test/org/apache/commons/lang/reflect/TestBean.java new file mode 100755 index 000000000..eb7e66c6c --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/TestBean.java @@ -0,0 +1,506 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/Attic/TestBean.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * General purpose test bean for JUnit tests for the "beanutils" component. + * + * @author Craig R. McClanahan + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +public class TestBean { + + + // ------------------------------------------------------------- Properties + + + /** + * A boolean property. + */ + private boolean booleanProperty = true; + + public boolean getBooleanProperty() { + return (booleanProperty); + } + + public void setBooleanProperty(boolean booleanProperty) { + this.booleanProperty = booleanProperty; + } + + + /** + * A boolean property that uses an "is" method for the getter. + */ + private boolean booleanSecond = true; + + public boolean isBooleanSecond() { + return (booleanSecond); + } + + public void setBooleanSecond(boolean booleanSecond) { + this.booleanSecond = booleanSecond; + } + + + /** + * A double property. + */ + private double doubleProperty = 321.0; + + public double getDoubleProperty() { + return (this.doubleProperty); + } + + public void setDoubleProperty(double doubleProperty) { + this.doubleProperty = doubleProperty; + } + + + /** + * An "indexed property" accessible via both array and subscript + * based getters and setters. + */ + private String dupProperty[] = + { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4" }; + + public String[] getDupProperty() { + return (this.dupProperty); + } + + public String getDupProperty(int index) { + return (this.dupProperty[index]); + } + + public void setDupProperty(int index, String value) { + this.dupProperty[index] = value; + } + + public void setDupProperty(String dupProperty[]) { + this.dupProperty = dupProperty; + } + + + /** + * A float property. + */ + private float floatProperty = (float) 123.0; + + public float getFloatProperty() { + return (this.floatProperty); + } + + public void setFloatProperty(float floatProperty) { + this.floatProperty = floatProperty; + } + + + /** + * An integer array property accessed as an array. + */ + private int intArray[] = { 0, 10, 20, 30, 40 }; + + public int[] getIntArray() { + return (this.intArray); + } + + public void setIntArray(int intArray[]) { + this.intArray = intArray; + } + + + /** + * An integer array property accessed as an indexed property. + */ + private int intIndexed[] = { 0, 10, 20, 30, 40 }; + + public int getIntIndexed(int index) { + return (intIndexed[index]); + } + + public void setIntIndexed(int index, int value) { + intIndexed[index] = value; + } + + + /** + * An integer property. + */ + private int intProperty = 123; + + public int getIntProperty() { + return (this.intProperty); + } + + public void setIntProperty(int intProperty) { + this.intProperty = intProperty; + } + + + /** + * A List property accessed as an indexed property. + */ + private static List listIndexed = new ArrayList(); + + static { + listIndexed.add("String 0"); + listIndexed.add("String 1"); + listIndexed.add("String 2"); + listIndexed.add("String 3"); + listIndexed.add("String 4"); + } + + public List getListIndexed() { + return (listIndexed); + } + + + /** + * A long property. + */ + private long longProperty = 321; + + public long getLongProperty() { + return (this.longProperty); + } + + public void setLongProperty(long longProperty) { + this.longProperty = longProperty; + } + + + /** + * A mapped property with only a getter and setter for a Map. + */ + private Map mapProperty = null; + + public Map getMapProperty() { + // Create the map the very first time + if (mapProperty == null) { + mapProperty = new HashMap(); + mapProperty.put("First Key", "First Value"); + mapProperty.put("Second Key", "Second Value"); + } + return (mapProperty); + } + + public void setMapProperty(Map mapProperty) { + // Create the map the very first time + if (mapProperty == null) { + mapProperty = new HashMap(); + mapProperty.put("First Key", "First Value"); + mapProperty.put("Second Key", "Second Value"); + } + this.mapProperty = mapProperty; + } + + + /** + * A mapped property that has String keys and Object values. + */ + private HashMap mappedObjects = null; + + public Object getMappedObjects(String key) { + // Create the map the very first time + if (mappedObjects == null) { + mappedObjects = new HashMap(); + mappedObjects.put("First Key", "First Value"); + mappedObjects.put("Second Key", "Second Value"); + } + return (mappedObjects.get(key)); + } + + public void setMappedObjects(String key, Object value) { + // Create the map the very first time + if (mappedObjects == null) { + mappedObjects = new HashMap(); + mappedObjects.put("First Key", "First Value"); + mappedObjects.put("Second Key", "Second Value"); + } + mappedObjects.put(key, value); + } + + + /** + * A mapped property that has String keys and String values. + */ + private HashMap mappedProperty = null; + + public String getMappedProperty(String key) { + // Create the map the very first time + if (mappedProperty == null) { + mappedProperty = new HashMap(); + mappedProperty.put("First Key", "First Value"); + mappedProperty.put("Second Key", "Second Value"); + } + return ((String) mappedProperty.get(key)); + } + + public void setMappedProperty(String key, String value) { + // Create the map the very first time + if (mappedProperty == null) { + mappedProperty = new HashMap(); + mappedProperty.put("First Key", "First Value"); + mappedProperty.put("Second Key", "Second Value"); + } + mappedProperty.put(key, value); + } + + + /** + * A mapped property that has String keys and int values. + */ + private HashMap mappedIntProperty = null; + + public int getMappedIntProperty(String key) { + // Create the map the very first time + if (mappedProperty == null) { + mappedProperty = new HashMap(); + mappedProperty.put("One", new Integer(1)); + mappedProperty.put("Two", new Integer(2)); + } + Integer x = (Integer) mappedIntProperty.get(key); + return ((x == null) ? 0 : x.intValue()); + } + + public void setMappedIntProperty(String key, int value) { + mappedIntProperty.put(key, new Integer(value)); + } + + + /** + * A nested reference to another test bean (populated as needed). + */ + private TestBean nested = null; + + public TestBean getNested() { + if (nested == null) + nested = new TestBean(); + return (nested); + } + + + /* + * Another nested reference to a bean containing mapp properties + */ + class MappedTestBean { + public void setValue(String key,String val) { } + public String getValue(String key) { return "Mapped Value"; } + } + + private MappedTestBean mappedNested = null; + + public MappedTestBean getMappedNested() { + if (mappedNested == null) + { + mappedNested = new MappedTestBean(); + } + return mappedNested; + } + + /** + * A String property with an initial value of null. + */ + private String nullProperty = null; + + public String getNullProperty() { + return (this.nullProperty); + } + + public void setNullProperty(String nullProperty) { + this.nullProperty = nullProperty; + } + + + /** + * A read-only String property. + */ + private String readOnlyProperty = "Read Only String Property"; + + public String getReadOnlyProperty() { + return (this.readOnlyProperty); + } + + + /** + * A short property. + */ + private short shortProperty = (short) 987; + + public short getShortProperty() { + return (this.shortProperty); + } + + public void setShortProperty(short shortProperty) { + this.shortProperty = shortProperty; + } + + + /** + * A String array property accessed as a String. + */ + private String stringArray[] = + { "String 0", "String 1", "String 2", "String 3", "String 4" }; + + public String[] getStringArray() { + return (this.stringArray); + } + + public void setStringArray(String stringArray[]) { + this.stringArray = stringArray; + } + + + /** + * A String array property accessed as an indexed property. + */ + private String stringIndexed[] = + { "String 0", "String 1", "String 2", "String 3", "String 4" }; + + public String getStringIndexed(int index) { + return (stringIndexed[index]); + } + + public void setStringIndexed(int index, String value) { + stringIndexed[index] = value; + } + + + /** + * A String property. + */ + private String stringProperty = "This is a string"; + + public String getStringProperty() { + return (this.stringProperty); + } + + public void setStringProperty(String stringProperty) { + this.stringProperty = stringProperty; + } + + + /** + * A write-only String property. + */ + private String writeOnlyProperty = "Write Only String Property"; + + public String getWriteOnlyPropertyValue() { + return (this.writeOnlyProperty); + } + + public void setWriteOnlyProperty(String writeOnlyProperty) { + this.writeOnlyProperty = writeOnlyProperty; + } + + + // ------------------------------------------------------- Static Variables + + + /** + * A static variable that is accessed and updated via static methods + * for MethodUtils testing. + */ + private static int counter = 0; + + + /** + * Return the current value of the counter. + */ + public static int currentCounter() { + + return (counter); + + } + + + /** + * Increment the current value of the counter by 1. + */ + public static void incrementCounter() { + + incrementCounter(1); + + } + + + /** + * Increment the current value of the counter by the specified amount. + * + * @param amount Amount to be added to the current counter + */ + public static void incrementCounter(int amount) { + + counter += amount; + + } + + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PackageBean.java b/src/test/org/apache/commons/lang/reflect/priv/PackageBean.java new file mode 100644 index 000000000..18c3559c8 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PackageBean.java @@ -0,0 +1,114 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PackageBean.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + *

This class is designed to test the default access jvm problem workaround. + * The issue is that public methods of a public subclass contained in a default access + * superclass are returned by reflection but an IllegalAccessException is thrown + * when they are invoked.

+ * + *

This is the default access superclass

+ * + * @author Robert Burrell Donkin + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +class PackageBean { + + + // ----------------------------------------------------------- Constructors + + + /** + * Package private constructor - can only use factory method to create + * beans. + */ + PackageBean() { + + super(); + + } + + + // ------------------------------------------------------------- Properties + + + /** + */ + private String bar = "This is bar"; + + public String getBar() { + + return (this.bar); + + } + + public void setBar(String bar) { + + this.bar = bar; + + } + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PrivateBean.java b/src/test/org/apache/commons/lang/reflect/priv/PrivateBean.java new file mode 100644 index 000000000..be5944ca5 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PrivateBean.java @@ -0,0 +1,155 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PrivateBean.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + * Bean that has a private constructor that exposes properties via + * various mechanisms (based on property name): + *
    + *
  • foo - Via direct public method + *
  • bar - Via directly implemented interface + *
  • baz - Via indirectly implemented interface + *
+ * + * @author Craig R. McClanahan + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +class PrivateBean implements PrivateDirect { + + + // ----------------------------------------------------------- Constructors + + + /** + * Package private constructor - can only use factory method to create + * beans. + */ + PrivateBean() { + + super(); + + } + + + // ------------------------------------------------------------- Properties + + + /** + * A directly implemented property. + */ + private String foo = "This is foo"; + + public String getFoo() { + + return (this.foo); + + } + + + /** + * A property accessible via a directly implemented interface. + */ + private String bar = "This is bar"; + + public String getBar() { + + return (this.bar); + + } + + + /** + * A method accessible via a directly implemented interface. + */ + public String methodBar(String in) { + + return (in); + + } + + + /** + * A property accessible via an indirectly implemented interface. + */ + private String baz = "This is baz"; + + public String getBaz() { + + return (this.baz); + + } + + + /** + * A method accessible via an indirectly implemented interface. + */ + public String methodBaz(String in) { + + return (in); + + } + + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanFactory.java b/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanFactory.java new file mode 100644 index 000000000..e405b497d --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanFactory.java @@ -0,0 +1,97 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PrivateBeanFactory.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + * Factory class for PrivateBean instances. + * + * @author Craig R. McClanahan + * @author Jan Sorensen + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +public class PrivateBeanFactory { + + + /** + * Factory method to create new beans. + */ + public static PrivateDirect create() { + + return (new PrivateBean()); + + } + + + /** + * Factory method to create new beans. + */ + public static PrivateDirect createSubclass() { + + return (new PrivateBeanSubclass()); + + } + + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanSubclass.java b/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanSubclass.java new file mode 100644 index 000000000..8aa86bdc4 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PrivateBeanSubclass.java @@ -0,0 +1,103 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PrivateBeanSubclass.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + * Bean that exposes methods defined by an interface that is implemented + * in the superclass. + * + * @author Jan Sorensen + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +class PrivateBeanSubclass extends PrivateBean { + + + // ----------------------------------------------------------- Constructors + + + /** + * Create a new PrivateBeanSubclass instance. + */ + PrivateBeanSubclass() { + + super(); + + } + + + // ------------------------------------------------------------- Properties + + + /** + * A property accessible via the superclass. + */ + public String getBar() { + + return (super.getBar()); + + } + + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PrivateDirect.java b/src/test/org/apache/commons/lang/reflect/priv/PrivateDirect.java new file mode 100644 index 000000000..6eae95f0d --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PrivateDirect.java @@ -0,0 +1,90 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PrivateDirect.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + * Interface that is directly implemented by PrivateBean. + * + * @author Craig R. McClanahan + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +public interface PrivateDirect extends PrivateIndirect { + + + // ------------------------------------------------------------- Properties + + + /** + * A property accessible via a directly implemented interface. + */ + String getBar(); + + + /** + * A method accessible via a directly implemented interface. + */ + String methodBar(String in); + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PrivateIndirect.java b/src/test/org/apache/commons/lang/reflect/priv/PrivateIndirect.java new file mode 100644 index 000000000..3a0976ab5 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PrivateIndirect.java @@ -0,0 +1,91 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PrivateIndirect.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + * Interface that is indirectly implemented by PrivateBean. + * + * @author Craig R. McClanahan + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +public interface PrivateIndirect { + + + // ------------------------------------------------------------- Properties + + + /** + * A property accessible via an indirectly implemented interface. + */ + public String getBaz(); + + + /** + * A method accessible via an indirectly implemented interface. + */ + public String methodBaz(String in); + + +} diff --git a/src/test/org/apache/commons/lang/reflect/priv/PublicSubBean.java b/src/test/org/apache/commons/lang/reflect/priv/PublicSubBean.java new file mode 100644 index 000000000..80cbbaca8 --- /dev/null +++ b/src/test/org/apache/commons/lang/reflect/priv/PublicSubBean.java @@ -0,0 +1,114 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//lang/src/test/org/apache/commons/lang/reflect/priv/Attic/PublicSubBean.java,v 1.1 2002/11/14 18:53:36 rdonkin Exp $ + * $Revision: 1.1 $ + * $Date: 2002/11/14 18:53:36 $ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + + +package org.apache.commons.lang.reflect.priv; + + +/** + *

This class is designed to test the default access jvm problem workaround. + * The issue is that public methods of a public subclass contained in a default access + * superclass are returned by reflection but an IllegalAccessException is thrown + * when they are invoked.

+ * + *

This is the default access superclass

+ * + * @author Robert Burrell Donkin + * @version $Revision: 1.1 $ $Date: 2002/11/14 18:53:36 $ + */ + +public class PublicSubBean extends PackageBean { + + + // ----------------------------------------------------------- Constructors + + + /** + * Package private constructor - can only use factory method to create + * beans. + */ + public PublicSubBean() { + + super(); + + } + + + // ------------------------------------------------------------- Properties + + + /** + * A directly implemented property. + */ + private String foo = "This is foo"; + + public String getFoo() { + + return (this.foo); + + } + + public void setFoo(String foo) { + + this.foo = foo; + + } +}