This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 35c30d08f [ISSUE #3275] improve unit test coverage of 'ReflectUtils
(#4215)
35c30d08f is described below
commit 35c30d08f5203f10659d5205ca764350a8e95d91
Author: xcsnx <[email protected]>
AuthorDate: Mon Nov 28 16:46:24 2022 +0800
[ISSUE #3275] improve unit test coverage of 'ReflectUtils (#4215)
* test common: Improve the test coverage of 'ReflectUtils'
* test common: Improve the test coverage of 'ReflectUtils'
Co-authored-by: ‘xcsnx’ <‘[email protected]’>
Co-authored-by: xiaoyu <[email protected]>
Co-authored-by: likeguo <[email protected]>
---
.../shenyu/common/utils/ReflectUtilsTest.java | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/utils/ReflectUtilsTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/utils/ReflectUtilsTest.java
index 78407f25d..2cce46bbb 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/utils/ReflectUtilsTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/utils/ReflectUtilsTest.java
@@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test cases for ReflectUtils.
@@ -44,8 +46,38 @@ public final class ReflectUtilsTest {
assertEquals("2", ReflectUtils.getFieldValue(reflect, "a"));
}
+ @Test
+ public void testInvokeStaticMethod() {
+ final Reflect reflect = new Reflect();
+ assertEquals("1", ReflectUtils.invokeStaticMethod(reflect.getClass(),
"methodStaticA"));
+ assertNull(ReflectUtils.invokeStaticMethod(reflect.getClass(),
"methodB"));
+ }
+
+ @Test
+ public void testInvokeMethod() {
+ final Reflect reflect = new Reflect();
+ assertEquals("1", ReflectUtils.invokeMethod(reflect, "methodA"));
+ }
+
+ @Test
+ public void testIsPrimitives() {
+ final Reflect reflect = new Reflect();
+ Integer[] test = new Integer[]{};
+ assertFalse(ReflectUtils.isPrimitives(reflect.getClass()));
+ assertFalse(ReflectUtils.isPrimitives(reflect.getClass()));
+ assertTrue(ReflectUtils.isPrimitives(test.getClass()));
+ }
+
static class Reflect {
private final String a = "1";
+
+ public static String methodStaticA() {
+ return "1";
+ }
+
+ public String methodA() {
+ return "1";
+ }
}
static class ReflectNonField {