Skip to content

Commit bed735b

Browse files
committed
Update MethodUtilsTest.java
1 parent 8d525e0 commit bed735b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

microsphere-java-core/src/test/java/io/microsphere/reflect/MethodUtilsTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package io.microsphere.reflect;
1818

1919
import io.microsphere.lang.Prioritized;
20+
import org.junit.jupiter.api.AfterAll;
21+
import org.junit.jupiter.api.BeforeEach;
2022
import org.junit.jupiter.api.Test;
2123

2224
import java.lang.reflect.Method;
@@ -28,6 +30,7 @@
2830

2931
import static io.microsphere.AbstractTestCase.JACOCO_AGENT_INSTRUCTED;
3032
import static io.microsphere.reflect.MemberUtils.PUBLIC_MEMBER_PREDICATE;
33+
import static io.microsphere.reflect.MethodUtils.BANNED_METHODS_PROPERTY_NAME;
3134
import static io.microsphere.reflect.MethodUtils.FINAL_METHOD_PREDICATE;
3235
import static io.microsphere.reflect.MethodUtils.NON_PRIVATE_METHOD_PREDICATE;
3336
import static io.microsphere.reflect.MethodUtils.NON_STATIC_METHOD_PREDICATE;
@@ -37,6 +40,7 @@
3740
import static io.microsphere.reflect.MethodUtils.STATIC_METHOD_PREDICATE;
3841
import static io.microsphere.reflect.MethodUtils.buildKey;
3942
import static io.microsphere.reflect.MethodUtils.buildSignature;
43+
import static io.microsphere.reflect.MethodUtils.clearBannedMethods;
4044
import static io.microsphere.reflect.MethodUtils.excludedDeclaredClass;
4145
import static io.microsphere.reflect.MethodUtils.findAllDeclaredMethods;
4246
import static io.microsphere.reflect.MethodUtils.findAllMethods;
@@ -50,13 +54,15 @@
5054
import static io.microsphere.reflect.MethodUtils.getDeclaredMethods;
5155
import static io.microsphere.reflect.MethodUtils.getMethods;
5256
import static io.microsphere.reflect.MethodUtils.getSignature;
57+
import static io.microsphere.reflect.MethodUtils.initBannedMethods;
5358
import static io.microsphere.reflect.MethodUtils.invokeMethod;
5459
import static io.microsphere.reflect.MethodUtils.invokeStaticMethod;
5560
import static io.microsphere.reflect.MethodUtils.isObjectMethod;
5661
import static io.microsphere.reflect.MethodUtils.overrides;
5762
import static io.microsphere.util.ArrayUtils.EMPTY_CLASS_ARRAY;
5863
import static io.microsphere.util.ClassUtils.PRIMITIVE_TYPES;
5964
import static java.lang.Integer.valueOf;
65+
import static java.lang.System.setProperty;
6066
import static java.util.Collections.emptyList;
6167
import static org.junit.jupiter.api.Assertions.assertEquals;
6268
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -80,6 +86,17 @@ class MethodUtilsTest {
8086
JACOCO_ADDED_METHOD_COUNT = JACOCO_AGENT_INSTRUCTED ? 1 : 0;
8187
}
8288

89+
@BeforeEach
90+
void setUp() {
91+
afterAll();
92+
}
93+
94+
@AfterAll
95+
static void afterAll() {
96+
System.getProperties().remove(BANNED_METHODS_PROPERTY_NAME);
97+
clearBannedMethods();
98+
}
99+
83100
@Test
84101
void testSTATIC_METHOD_PREDICATE() {
85102
assertTrue(STATIC_METHOD_PREDICATE.test(findMethod(ReflectionTest.class, "staticMethod")));
@@ -107,6 +124,23 @@ void testNON_PRIVATE_METHOD_PREDICATE() {
107124
assertTrue(NON_PRIVATE_METHOD_PREDICATE.test(findMethod(ReflectionTest.class, "packagePrivateMethod", String.class)));
108125
}
109126

127+
@Test
128+
void testInitBannedMethods() {
129+
String signature = buildSignature(String.class, "substring", int.class);
130+
String signature2 = buildSignature(String.class, "substring", int.class, int.class);
131+
setProperty(BANNED_METHODS_PROPERTY_NAME, signature + " | " + signature2);
132+
initBannedMethods();
133+
assertNull(findMethod(String.class, "substring", int.class));
134+
assertNull(findMethod(String.class, "substring", int.class, int.class));
135+
}
136+
137+
@Test
138+
void testInitBannedMethodsWithoutProperty() {
139+
initBannedMethods();
140+
assertNotNull(findMethod(String.class, "substring", int.class));
141+
assertNotNull(findMethod(String.class, "substring", int.class, int.class));
142+
}
143+
110144
@Test
111145
void testExcludedDeclaredClass() {
112146
Predicate<? super Method> predicate = excludedDeclaredClass(Object.class);

0 commit comments

Comments
 (0)