Skip to content

ParameterizedRunnerToParameterized: migrate classes whose @Parameters method is inherited - #1139

Open
mohitduhan19 wants to merge 6 commits into
openrewrite:mainfrom
mohitduhan19:fix-1126-inherited-parameters
Open

mohitduhan19 wants to merge 6 commits into
openrewrite:mainfrom
mohitduhan19:fix-1126-inherited-parameters

Conversation

@mohitduhan19

Copy link
Copy Markdown
Contributor

What's changed?

ParameterizedRunnerToParameterized only migrated a @RunWith(Parameterized.class) class when its @Parameters factory was declared in that same class. When the factory is inherited from a superclass, the recipe now finds it on the supertype and references it the way @MethodSource accepts for a method outside the test class, e.g. @MethodSource("com.example.ParamBase#data"). The factory's name is carried over as @ParameterizedTest(name = ...). This works for both constructor and @Parameter field injection.

When the constructor passes its arguments on to the superclass constructor (super(value)), a Jupiter parameterized test method can't supply them, so rather than half-migrate the class the recipe now leaves it as is and adds a search marker explaining why, as the issue suggests.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

  • The inherited factory's display name is read from its type attribution (JavaType.Annotation values), since the superclass is usually in another source file.
  • The two migrating tests relax method invocation type validation on the after source only: as in nestedRunners, the inserted init... call isn't attributed when the class extends a type that is only available as source.
  • The superclass keeps its JUnit 4 @Parameters annotation, since removing it could break other subclasses that aren't (or can't be) migrated.
  • The new logic only runs when a @RunWith(Parameterized.class) class declares no @Parameters method of its own, so existing migrations are unchanged.

Have you considered any alternatives or workarounds?

The super(...) case could be migrated fully with JUnit 5.13's @ParameterizedClass and constructor injection. That felt like a larger design choice, so I kept to the search marker here; happy to follow up if you'd like that direction.

Any additional context

All three new tests fail on main ("Recipe was expected to make a change but made no changes") and pass with this change, along with the rest of ParameterizedRunnerToParameterizedTest, EnclosedToNestedTest and JunitMockitoUpgradeIntegrationTest. I couldn't run the full Gradle build in my environment, so CI will be the first full run.

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

ParameterizedRunnerToParameterized silently skips classes whose @Parameters method is inherited, leaving a partially migrated class that

1 participant