4646import org .springframework .javapoet .CodeBlock ;
4747import org .springframework .test .context .DynamicPropertyRegistry ;
4848import org .springframework .test .context .DynamicPropertySource ;
49+ import org .springframework .test .util .ReflectionTestUtils ;
4950import org .springframework .util .Assert ;
5051import org .springframework .util .ClassUtils ;
5152import org .springframework .util .ReflectionUtils ;
@@ -201,7 +202,6 @@ private static GeneratedMethod generateMethod(GenerationContext generationContex
201202 code .addModifiers (javax .lang .model .element .Modifier .PRIVATE ,
202203 javax .lang .model .element .Modifier .STATIC );
203204 code .addParameter (DynamicPropertyRegistry .class , DYNAMIC_PROPERTY_REGISTRY );
204-
205205 if (isMethodAccessible (generatedClass , method )) {
206206 code .addStatement (CodeBlock .of ("$T.$L($L)" , method .getDeclaringClass (), method .getName (),
207207 DYNAMIC_PROPERTY_REGISTRY ));
@@ -211,12 +211,9 @@ private static GeneratedMethod generateMethod(GenerationContext generationContex
211211 code .beginControlFlow ("try" );
212212 code .addStatement ("$T<?> clazz = $T.forName($S, $T.class.getClassLoader())" , Class .class ,
213213 ClassUtils .class , ClassName .get (method .getDeclaringClass ()), generatedClass .getName ());
214- code .addStatement ("$T method = $T.findMethod(clazz, $S, $T.class)" , Method .class ,
215- ReflectionUtils .class , method .getName (), DynamicPropertyRegistry .class );
216- code .addStatement ("$T.notNull(method, $S)" , Assert .class ,
217- "Method '" + method .getName () + "' is not found" );
218- code .addStatement ("$T.makeAccessible(method)" , ReflectionUtils .class );
219- code .addStatement ("$T.invokeMethod(method, null, $L)" , ReflectionUtils .class ,
214+ // ReflectionTestUtils can be used here because
215+ // @DynamicPropertyRegistry in a test module.
216+ code .addStatement ("$T.invokeMethod(clazz, $S, $L)" , ReflectionTestUtils .class , method .getName (),
220217 DYNAMIC_PROPERTY_REGISTRY );
221218 code .nextControlFlow ("catch ($T ex)" , ClassNotFoundException .class );
222219 code .addStatement ("throw new $T(ex)" , RuntimeException .class );
0 commit comments