Browse Source

[SPR-8644][SPR-8633] introduced failing (ignored) test regarding support for invoking methods that accept var-args.

pull/7/head
Sam Brannen 15 years ago
parent
commit
1a34f6459d
  1. 22
      org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java
  2. 20
      org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java

22
org.springframework.test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java

@ -24,6 +24,7 @@ import static org.springframework.test.util.ReflectionTestUtils.invokeMethod; @@ -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 { @@ -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 { @@ -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)

20
org.springframework.test/src/test/java/org/springframework/test/util/subpackage/Component.java

@ -62,8 +62,24 @@ public class Component { @@ -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;
}
}

Loading…
Cancel
Save