1717package io .microsphere .reflect ;
1818
1919import io .microsphere .lang .Prioritized ;
20+ import org .junit .jupiter .api .AfterAll ;
21+ import org .junit .jupiter .api .BeforeEach ;
2022import org .junit .jupiter .api .Test ;
2123
2224import java .lang .reflect .Method ;
2830
2931import static io .microsphere .AbstractTestCase .JACOCO_AGENT_INSTRUCTED ;
3032import static io .microsphere .reflect .MemberUtils .PUBLIC_MEMBER_PREDICATE ;
33+ import static io .microsphere .reflect .MethodUtils .BANNED_METHODS_PROPERTY_NAME ;
3134import static io .microsphere .reflect .MethodUtils .FINAL_METHOD_PREDICATE ;
3235import static io .microsphere .reflect .MethodUtils .NON_PRIVATE_METHOD_PREDICATE ;
3336import static io .microsphere .reflect .MethodUtils .NON_STATIC_METHOD_PREDICATE ;
3740import static io .microsphere .reflect .MethodUtils .STATIC_METHOD_PREDICATE ;
3841import static io .microsphere .reflect .MethodUtils .buildKey ;
3942import static io .microsphere .reflect .MethodUtils .buildSignature ;
43+ import static io .microsphere .reflect .MethodUtils .clearBannedMethods ;
4044import static io .microsphere .reflect .MethodUtils .excludedDeclaredClass ;
4145import static io .microsphere .reflect .MethodUtils .findAllDeclaredMethods ;
4246import static io .microsphere .reflect .MethodUtils .findAllMethods ;
5054import static io .microsphere .reflect .MethodUtils .getDeclaredMethods ;
5155import static io .microsphere .reflect .MethodUtils .getMethods ;
5256import static io .microsphere .reflect .MethodUtils .getSignature ;
57+ import static io .microsphere .reflect .MethodUtils .initBannedMethods ;
5358import static io .microsphere .reflect .MethodUtils .invokeMethod ;
5459import static io .microsphere .reflect .MethodUtils .invokeStaticMethod ;
5560import static io .microsphere .reflect .MethodUtils .isObjectMethod ;
5661import static io .microsphere .reflect .MethodUtils .overrides ;
5762import static io .microsphere .util .ArrayUtils .EMPTY_CLASS_ARRAY ;
5863import static io .microsphere .util .ClassUtils .PRIMITIVE_TYPES ;
5964import static java .lang .Integer .valueOf ;
65+ import static java .lang .System .setProperty ;
6066import static java .util .Collections .emptyList ;
6167import static org .junit .jupiter .api .Assertions .assertEquals ;
6268import 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