rewrite-testing-frameworks
rewrite-testing-frameworks copied to clipboard
`RemoveTestPrefix` should not (only) rename methods called from other methods
Quickly noted down here, can be tackled individually.
- [x] Should not rename test when there's a static method import of the same name (can lead to conflicts)
- [ ] Should not (only) rename test method when called from other methods (which unfortunately happens)
Note: this issue is a bit more visible now that RemoveTestPrefix
is included in JUnit5BestPractices
: https://github.com/openrewrite/rewrite-testing-frameworks/commit/cb59832d19f6e44d6a9c5bc5e9f44860b377c3ad
Just to offer up a test case for the first issue listed above as we ran into this in our codebase:
@Test
void testRemoveTestPrefixWithClashingMethod() {
rewriteRun(
spec -> spec.recipe(new RemoveTestPrefix()),
java(
"""
package com.spotify.helloworld;
import org.junit.jupiter.api.Test;
import static java.util.List.of;
public class FooTest {
@Test
void testOf() {
of();
}
}"""));
}
I can put this test in a PR if that is preferable. Not sure I'd know how to fix it though.
Thanks @protocol7 ; this one was easy it seems;
- Fixed in https://github.com/openrewrite/rewrite-testing-frameworks/pull/543
We could maybe fix the remaining issue (within a single class) by switching to ChangeMethodName
in a doAfterVisit
instead of using the .withXyz()
methods in this recipe directly. But we'd need to correctly construct the method pattern to match from the method declaration to do so, and even then it would only work in a single compilation unit, not across.