Merge pull request #2912 from jptx1234/v5-dev

修复ReflectUtil.invokeRaw方法中参数类型转换动作未生效的问题
This commit is contained in:
Golden Looly
2023-02-21 15:55:55 +08:00
committed by GitHub
2 changed files with 27 additions and 1 deletions

View File

@@ -99,6 +99,30 @@ public class ReflectUtilTest {
Assert.assertEquals(10, testClass.getA());
}
@Test
public void invokeMethodTest() {
final TestClass testClass = new TestClass();
final Method method = ReflectUtil.getMethod(TestClass.class, "setA", int.class);
ReflectUtil.invoke(testClass, method, 10);
Assert.assertEquals(10, testClass.getA());
}
@Test
public void invokeMethodWithParamConvertTest() {
final TestClass testClass = new TestClass();
final Method method = ReflectUtil.getMethod(TestClass.class, "setA", int.class);
ReflectUtil.invoke(testClass, method, "10");
Assert.assertEquals(10, testClass.getA());
}
@Test
public void invokeMethodWithParamConvertFailedTest() {
final TestClass testClass = new TestClass();
final Method method = ReflectUtil.getMethod(TestClass.class, "setA", int.class);
Assert.assertThrows(IllegalArgumentException.class,
() -> ReflectUtil.invoke(testClass, method, "NaN"));
}
@Test
public void noneStaticInnerClassTest() {
final NoneStaticClass testAClass = ReflectUtil.newInstanceIfPossible(NoneStaticClass.class);