From 1d41504168f1d23534d408ef53b54a14ba2d2126 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Mon, 27 Jun 2011 04:58:35 +0000 Subject: [PATCH] [LANG-709] Increase test coverage of MethodUtils invoke methods and a few test corrections git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1140015 13f79535-47bb-0310-9956-ffa450edef68 --- .../lang3/reflect/MethodUtilsTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java index ccfae62f3..b3409f7f5 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java @@ -117,6 +117,8 @@ public void testInvokeMethod() throws Exception { (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY)); assertEquals("foo()", MethodUtils.invokeMethod(testBean, "foo", (Object[]) null)); + assertEquals("foo()", MethodUtils.invokeMethod(testBean, "foo", + (Object[]) null, (Class[]) null)); assertEquals("foo(String)", MethodUtils.invokeMethod(testBean, "foo", "")); assertEquals("foo(Object)", MethodUtils.invokeMethod(testBean, "foo", @@ -134,10 +136,12 @@ public void testInvokeMethod() throws Exception { } public void testInvokeExactMethod() throws Exception { - assertEquals("foo()", MethodUtils.invokeMethod(testBean, "foo", + assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo", (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY)); - assertEquals("foo()", MethodUtils.invokeMethod(testBean, "foo", + assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo", (Object[]) null)); + assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo", + (Object[]) null, (Class[]) null)); assertEquals("foo(String)", MethodUtils.invokeExactMethod(testBean, "foo", "")); assertEquals("foo(Object)", MethodUtils.invokeExactMethod(testBean, @@ -172,6 +176,8 @@ public void testInvokeStaticMethod() throws Exception { "bar", (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY)); assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar", (Object[]) null)); + assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, + "bar", (Object[]) null, (Class[]) null)); assertEquals("bar(String)", MethodUtils.invokeStaticMethod( TestBean.class, "bar", "")); assertEquals("bar(Object)", MethodUtils.invokeStaticMethod( @@ -186,13 +192,21 @@ public void testInvokeStaticMethod() throws Exception { TestBean.class, "bar", NumberUtils.LONG_ONE)); assertEquals("bar(double)", MethodUtils.invokeStaticMethod( TestBean.class, "bar", NumberUtils.DOUBLE_ONE)); + + try { + MethodUtils.invokeStaticMethod(TestBean.class, "does_not_exist"); + fail("should throw NoSuchMethodException"); + } catch (NoSuchMethodException e) { + } } public void testInvokeExactStaticMethod() throws Exception { - assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, + assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class, "bar", (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY)); - assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, + assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class, "bar", (Object[]) null)); + assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class, + "bar", (Object[]) null, (Class[]) null)); assertEquals("bar(String)", MethodUtils.invokeExactStaticMethod( TestBean.class, "bar", "")); assertEquals("bar(Object)", MethodUtils.invokeExactStaticMethod(