1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.beanutils.bugs;
18
19 import java.lang.reflect.Method;
20
21 import junit.framework.TestCase;
22
23 import org.apache.commons.beanutils.MethodUtils;
24
25 /**
26 * MethodUtils's getMatchingAccessibleMethod() does not correctly
27 * handle inheritance and method overloading.
28 *
29 * @version $Id$
30 * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-381">https://issues.apache.org/jira/browse/BEANUTILS-381</a>
31 */
32 public class Jira381TestCase extends TestCase {
33
34 /**
35 * Create a test case with the specified name.
36 *
37 * @param name The name of the test
38 */
39 public Jira381TestCase(final String name) {
40 super(name);
41 }
42
43 /**
44 * Test with an private class that overrides a public method
45 * of a "grand parent" public class.
46 * <p />
47 * See Jira issue# BEANUTILS-381.
48 */
49 public void testIssue_BEANUTILS_381_getMatchingAccessibleMethod() {
50
51 final Class<?> target = TestServiceBean.class;
52 final String methodName = "performOp";
53 final Class<?>[] runtimeClasses = new Class<?>[]{TestObjectSubclass.class};
54
55 final Method returned = MethodUtils.getMatchingAccessibleMethod(target, methodName, runtimeClasses);
56
57 assertEquals(target, returned.getDeclaringClass());
58 assertEquals(methodName, returned.getName());
59 assertEquals(TestObject.class, returned.getParameterTypes()[0]);
60 }
61
62 /**
63 * Test bean.
64 */
65 public class TestServiceBean{
66
67 /**
68 * Generic object method
69 */
70 public void performOp(final Object o){
71 }
72
73 /**
74 * Object method
75 */
76 public void performOp(final TestObject o){
77 }
78 }
79
80 /**
81 * Test object.
82 *
83 */
84 public class TestObject{
85 }
86
87 /**
88 * Used to match performop with test object
89 */
90 public class TestObjectSubclass extends TestObject{
91 }
92 }