Additional tests for MethodUtils from Nathan Beyer - LANG-712

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1142380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2011-07-03 06:59:59 +00:00
parent e3cb1c6c0a
commit f5cb67acd9
1 changed files with 27 additions and 0 deletions

View File

@ -33,6 +33,15 @@ import org.apache.commons.lang3.mutable.MutableObject;
* @version $Id$ * @version $Id$
*/ */
public class MethodUtilsTest extends TestCase { public class MethodUtilsTest extends TestCase {
private static interface PrivateInterface {}
static class TestBeanWithInterfaces implements PrivateInterface {
public String foo() {
return "foo()";
}
}
public static class TestBean { public static class TestBean {
public static String bar() { public static String bar() {
@ -59,6 +68,11 @@ public class MethodUtilsTest extends TestCase {
return "bar(Object)"; return "bar(Object)";
} }
@SuppressWarnings("unused")
private void privateStuff() {
}
public String foo() { public String foo() {
return "foo()"; return "foo()";
} }
@ -248,6 +262,13 @@ public class MethodUtilsTest extends TestCase {
} }
} }
public void testGetAccessibleMethodPrivateInterface() throws Exception {
Method expected = TestBeanWithInterfaces.class.getMethod("foo");
assertNotNull(expected);
Method actual = MethodUtils.getAccessibleMethod(TestBeanWithInterfaces.class, "foo");
assertNull(actual);
}
public void testGetAccessibleInterfaceMethodFromDescription() public void testGetAccessibleInterfaceMethodFromDescription()
throws Exception { throws Exception {
Class<?>[][] p = { ArrayUtils.EMPTY_CLASS_ARRAY, null }; Class<?>[][] p = { ArrayUtils.EMPTY_CLASS_ARRAY, null };
@ -270,6 +291,12 @@ public class MethodUtilsTest extends TestCase {
.getDeclaringClass()); .getDeclaringClass());
} }
public void testGetAccessibleMethodInaccessible() throws Exception {
Method expected = TestBean.class.getDeclaredMethod("privateStuff");
Method actual = MethodUtils.getAccessibleMethod(expected);
assertNull(actual);
}
public void testGetMatchingAccessibleMethod() throws Exception { public void testGetMatchingAccessibleMethod() throws Exception {
expectMatchingAccessibleMethodParameterTypes(TestBean.class, "foo", expectMatchingAccessibleMethodParameterTypes(TestBean.class, "foo",
ArrayUtils.EMPTY_CLASS_ARRAY, ArrayUtils.EMPTY_CLASS_ARRAY); ArrayUtils.EMPTY_CLASS_ARRAY, ArrayUtils.EMPTY_CLASS_ARRAY);