ParameterizedRunnerToParameterized update to account for test class inheritance
Discovered while applying JUnit4To5Migration on Antlr
For tests classes that inherit from a superclass and have a constructor which invokes the superclass constructor:
- compare super constructor parameters with the MethodSource parameters
- modify super constructor if necessary
- add init method to class and superclass if necessary
before:
public class BaseRuntimeTest {
public BaseRuntimeTest(RuntimeTestDescriptor descriptor, RuntimeTestSupport delegate) {
this.descriptor = descriptor;
this.delegate = delegate;
}
}
public class TestPerformance extends BaseRuntimeTest {
public TestPerformance(RuntimeTestDescriptor descriptor) {
super(descriptor,new BaseGoTest());
}
}
after:
public class BaseRuntimeTest {
public BaseRuntimeTest(RuntimeTestSupport delegate) {
this.delegate = delegate;
}
public void initBaseRuntimeTest(RuntimeTestDescriptor descriptor){
this.descriptor = descriptor;
}
}
public class TestPerformance extends BaseRuntimeTest {
public TestPerformance() {
super(new BaseGoTest());
}
public void initTestPerformance(RuntimeTestDescriptor descriptor) {
initBaseRuntimeTest(descriptor);
}
}
This requires https://github.com/openrewrite/rewrite/issues/150
This has been kicking around since March and we haven't prioritized it. Once we implement openrewrite/rewrite#150 we can revisit issues like this.
Re-Opening given that 7.17.0 has better JavaType information
The current recipe implementation replaces the constructor with the initialize method. Applying this logic to the BaseTest and deleting the constructor may conflict with other usages. This could lead to failing migrations or builds.
I've implemented a test case to reproduce in ParameterizedRunnerToParameterizedTest and implemented a first version of the required changes in the test methods. Currently the migration of the base class is missing.