diff --git a/org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java b/org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java index e98018d0fa..f707fdc40c 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java @@ -24,6 +24,7 @@ import static org.springframework.test.util.ReflectionTestUtils.invokeMethod; import static org.springframework.test.util.ReflectionTestUtils.invokeSetterMethod; import static org.springframework.test.util.ReflectionTestUtils.setField; +import org.junit.Ignore; import org.junit.Test; import org.springframework.test.AssertThrows; import org.springframework.test.util.subpackage.Component; @@ -201,9 +202,22 @@ public class ReflectionTestUtilsTests { } @Test - public void invokeMethodWithReturnValueWithAutoboxingAndUnboxing() { - int sum = invokeMethod(component, "add", 1, 2); - assertEquals("add(1, 2)", 3, sum); + public void invokeMethodWithAutoboxingAndUnboxing() { + int difference = invokeMethod(component, "subtract", 5, 2); + assertEquals("subtract(5, 2)", 3, difference); + } + + @Ignore("[SPR-8644] findMethod() does not currently support var-args") + @Test + public void invokeMethodWithPrimitiveVarArgs() { + int sum = invokeMethod(component, "add", 1, 2, 3, 4); + assertEquals("add(1,2,3,4)", 10, sum); + } + + @Test + public void invokeMethodWithPrimitiveVarArgsAsSingleArgument() { + int sum = invokeMethod(component, "add", new int[] { 1, 2, 3, 4 }); + assertEquals("add(1,2,3,4)", 10, sum); } @Test @@ -228,7 +242,7 @@ public class ReflectionTestUtilsTests { @Test(expected = IllegalStateException.class) public void invokeMethodWithIncompatibleArgumentTypes() { - invokeMethod(component, "add", "foo", 2.0); + invokeMethod(component, "subtract", "foo", 2.0); } @Test(expected = IllegalStateException.class) diff --git a/org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java b/org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java index 64ecff8e0c..edb2e71904 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java +++ b/org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java @@ -62,8 +62,24 @@ public class Component { this.text = null; } - int add(int a, int b) { - return a + b; + int subtract(int a, int b) { + return a - b; + } + + int add(int... args) { + int sum = 0; + for (int i = 0; i < args.length; i++) { + sum += args[i]; + } + return sum; + } + + int multiply(Integer... args) { + int product = 1; + for (int i = 0; i < args.length; i++) { + product *= args[i]; + } + return product; } }