This commit is contained in:
Looly
2023-02-20 09:49:29 +08:00
parent 65d75e8b8a
commit 76e742ec0c
2 changed files with 31 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.lang.test.bean.ExamInfoDict;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.SystemUtil; import cn.hutool.core.util.SystemUtil;
import lombok.Data;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@@ -216,4 +217,33 @@ public class MethodUtilTest {
} }
} }
} }
@Data
static class TestClass {
private int a;
}
@Test
public void invokeMethodTest() {
final TestClass testClass = new TestClass();
final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class);
MethodUtil.invoke(testClass, method, 10);
Assert.assertEquals(10, testClass.getA());
}
@Test
public void invokeMethodWithParamConvertTest() {
final TestClass testClass = new TestClass();
final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class);
MethodUtil.invoke(testClass, method, "10");
Assert.assertEquals(10, testClass.getA());
}
@Test
public void invokeMethodWithParamConvertFailedTest() {
final TestClass testClass = new TestClass();
final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class);
Assert.assertThrows(IllegalArgumentException.class,
() -> MethodUtil.invoke(testClass, method, "NaN"));
}
} }

View File

@@ -479,7 +479,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>QLExpress</artifactId> <artifactId>QLExpress</artifactId>
<version>3.3.0</version> <version>3.3.1</version>
<scope>compile</scope> <scope>compile</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>