@@ -50,6 +50,7 @@ public class JUnitParamsRunnerToParameterized extends Recipe {
50
50
51
51
private static final String INIT_METHOD_REFERENCES = "init-method-references" ;
52
52
private static final String PARAMETERS_FOR_PREFIX = "parametersFor" ;
53
+ private static final String PARAMETERIZED_TESTS = "parameterized-tests" ;
53
54
private static final String INIT_METHODS_MAP = "named-parameters-map" ;
54
55
private static final String CONVERSION_NOT_SUPPORTED = "conversion-not-supported" ;
55
56
@@ -82,6 +83,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
82
83
doAfterVisit (new ParametersNoArgsImplicitMethodSource (initMethods ,
83
84
getCursor ().computeMessageIfAbsent (INIT_METHODS_MAP , v -> new HashMap <>()),
84
85
getCursor ().computeMessageIfAbsent (CONVERSION_NOT_SUPPORTED , v -> new HashSet <>()),
86
+ getCursor ().computeMessageIfAbsent (PARAMETERIZED_TESTS , v -> new HashSet <>()),
85
87
ctx ));
86
88
}
87
89
return cd ;
@@ -103,6 +105,8 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
103
105
J .Annotation anno = super .visitAnnotation (annotation , ctx );
104
106
Cursor classDeclCursor = getCursor ().dropParentUntil (J .ClassDeclaration .class ::isInstance );
105
107
if (PARAMETERS_MATCHER .matches (anno )) {
108
+ classDeclCursor .computeMessageIfAbsent (PARAMETERIZED_TESTS , v -> new HashSet <>())
109
+ .add (getCursor ().firstEnclosing (J .MethodDeclaration .class ).getSimpleName ());
106
110
String annotationArgumentValue = getAnnotationArgumentForInitMethod (anno , "method" , "named" );
107
111
if (annotationArgumentValue != null ) {
108
112
for (String method : annotationArgumentValue .split ("," )) {
@@ -178,16 +182,18 @@ private static class ParametersNoArgsImplicitMethodSource extends JavaIsoVisitor
178
182
179
183
private final Set <String > initMethods ;
180
184
private final Set <String > unsupportedConversions ;
185
+ private final Set <String > parameterizedTests ;
181
186
private final Map <String , String > initMethodReferences ;
182
187
183
188
private final JavaTemplate parameterizedTestTemplate ;
184
189
private final JavaTemplate parameterizedTestTemplateWithName ;
185
190
private final JavaTemplate methodSourceTemplate ;
186
191
187
- public ParametersNoArgsImplicitMethodSource (Set <String > initMethods , Map <String , String > initMethodReferences , Set <String > unsupportedConversions , ExecutionContext ctx ) {
192
+ public ParametersNoArgsImplicitMethodSource (Set <String > initMethods , Map <String , String > initMethodReferences , Set <String > unsupportedConversions , Set < String > parameterizedTests , ExecutionContext ctx ) {
188
193
this .initMethods = initMethods ;
189
194
this .initMethodReferences = initMethodReferences ;
190
195
this .unsupportedConversions = unsupportedConversions ;
196
+ this .parameterizedTests = parameterizedTests ;
191
197
192
198
// build @ParameterizedTest template
193
199
JavaParser .Builder <?, ?> javaParser = JavaParser .fromJavaVersion ()
@@ -254,6 +260,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
254
260
255
261
private J .Annotation maybeReplaceTestAnnotation (Cursor anno , @ Nullable String parameterizedTestArgument ) {
256
262
if (JUPITER_TEST_ANNOTATION_MATCHER .matches (anno .getValue ()) || JUNIT_TEST_ANNOTATION_MATCHER .matches (anno .getValue ())) {
263
+ if (!parameterizedTests .contains (anno .firstEnclosing (J .MethodDeclaration .class ).getSimpleName ())) {
264
+ return anno .getValue ();
265
+ }
257
266
if (parameterizedTestArgument == null ) {
258
267
return parameterizedTestTemplate .apply (anno , ((J .Annotation ) anno .getValue ()).getCoordinates ().replace ());
259
268
} else {
0 commit comments