You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/29 19:45:46 UTC

(commons-lang) 04/05: Add and rename tests in MethodUtilsTest

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 089be860f16719aaa4ea8290a8c393de0b7dc7f6
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 29 14:24:44 2025 -0400

    Add and rename tests in MethodUtilsTest
---
 .../commons/lang3/reflect/MethodUtilsTest.java     | 41 ++++++++++++++++------
 1 file changed, 31 insertions(+), 10 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 be7be3b37..458d4d59c 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
@@ -211,10 +211,6 @@ public static String bar(final String... s) {
             return "bar(String...)";
         }
 
-        public static String intStringVarArg(final int intArg, final String... args) {
-            return "int, String...";
-        }
-
         // This method is overloaded for the wrapper class for every numeric primitive type, plus the common
         // supertype Number
         public static String numOverload(final Byte... args) {
@@ -249,6 +245,10 @@ public static void oneParameterStatic(final String s) {
             // empty
         }
 
+        public static String staticIntStringVarArg(final int intArg, final String... args) {
+            return "static int, String...";
+        }
+
         public static String varOverload(final Boolean... args) {
             return "Boolean...";
         }
@@ -374,6 +374,10 @@ public String foo(final String... s) {
             return "foo(String...)";
         }
 
+        public String intStringVarArg(final int intArg, final String... args) {
+            return "int, String...";
+        }
+
         public void oneParameter(final String s) {
             // empty
         }
@@ -1060,18 +1064,20 @@ void testInvokeMethod() throws Exception {
         assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeMethod(testBean, null, 1, 2));
     }
 
-    @Test
-    void testInvokeMethod_VarArgsNotUniqueResolvable() throws Exception {
-        assertEquals("Boolean...", MethodUtils.invokeMethod(testBean, "varOverload", new Object[] { null }));
-        assertEquals("Object...", MethodUtils.invokeMethod(testBean, "varOverload", (Object[]) null));
-    }
-
     @Test
     void testInvokeMethod_VarArgsWithNullValues() throws Exception {
         assertEquals("String...", MethodUtils.invokeMethod(testBean, "varOverload", "a", null, "c"));
         assertEquals("String...", MethodUtils.invokeMethod(testBean, "varOverload", "a", "b", null));
     }
 
+    @Test
+    void testInvokeMethod1PlusVarArgs() throws Exception {
+        // assertEquals("int, String...", MethodUtils.invokeMethod(testBean, "intStringVarArg", 1));
+        assertEquals("int, String...", MethodUtils.invokeMethod(testBean, "intStringVarArg", 1, "s"));
+        assertEquals("int, String...", MethodUtils.invokeMethod(testBean, "intStringVarArg", 1, "s1", "s2"));
+        assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeMethod(testBean, "intStringVarArg", 1, "s1", 5));
+    }
+
     @Test
     void testInvokeMethodForceAccessNoArgs() throws Exception {
         assertEquals("privateStringStuff()", MethodUtils.invokeMethod(testBean, true, "privateStringStuff"));
@@ -1087,6 +1093,12 @@ void testInvokeMethodForceAccessWithArgs() throws Exception {
         assertNullPointerException(() -> MethodUtils.invokeMethod(testBean, true, null, "Hi There"));
     }
 
+    @Test
+    void testInvokeMethodVarArgsNotUniqueResolvable() throws Exception {
+        assertEquals("Boolean...", MethodUtils.invokeMethod(testBean, "varOverload", new Object[] { null }));
+        assertEquals("Object...", MethodUtils.invokeMethod(testBean, "varOverload", (Object[]) null));
+    }
+
     @Test
     void testInvokeMethodVarArgsUnboxingBooleanArray() throws Exception {
         final TestBean testBean = new TestBean();
@@ -1153,6 +1165,7 @@ void testInvokeMethodVarArgsUnboxingShortArray() throws Exception {
 
     @Test
     void testInvokeStaticMethod() throws Exception {
+        assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar"));
         assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar", (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY));
         assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar", (Object[]) null));
         assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar", null, null));
@@ -1176,6 +1189,14 @@ void testInvokeStaticMethod() throws Exception {
         assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeStaticMethod(TestBean.class, "does_not_exist"));
     }
 
+    @Test
+    void testInvokeStaticMethod1PlusVarArgs() throws Exception {
+        // assertEquals("static int, String...", MethodUtils.invokeStaticMethod(TestBean.class, "staticIntStringVarArg", 1));
+        assertEquals("static int, String...", MethodUtils.invokeStaticMethod(TestBean.class, "staticIntStringVarArg", 1, "s"));
+        assertEquals("static int, String...", MethodUtils.invokeStaticMethod(TestBean.class, "staticIntStringVarArg", 1, "s1", "s2"));
+        assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeStaticMethod(TestBean.class, "staticIntStringVarArg", 1, "s1", 5));
+    }
+
     @Test
     void testNullArgument() {
         expectMatchingAccessibleMethodParameterTypes(TestBean.class, "oneParameter", singletonArray(null), singletonArray(String.class));