openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
77 stars 73 forks source link

`RemoveTestPrefix` does not check if a similarly named static import exists #569

Open blipper opened 3 months ago

blipper commented 3 months ago

What version of OpenRewrite are you using?

Latest

How are you running OpenRewrite?

gradle

What is the smallest, simplest way to reproduce the problem?

import static Bar.foo; 
@Test
class A {
    void testFoo() {
    }
}

What did you expect to see?

@Test
class A {
    void testFoo() {
    }
}

What did you see instead?

@Test
class A {
    void foo() {
    }
}

What is the full stack trace of any errors you encountered?

Compilation will fail

Are you interested in contributing a fix to OpenRewrite?

Yes

timtebeek commented 3 months ago

Thanks for the clear example and offer to help @blipper! Must say it's appreciated how diligently you're reporting issues you come across. Really helps fix any blind spots.

Your examples would fit right in as a unit test, similar to this earlier one: https://github.com/openrewrite/rewrite-testing-frameworks/blob/30f35fe919b8166c19ddf22e2f1ea1c0d918487a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java#L328-L347

Once there's a test we will likely want to add a similar exemption as seen here: https://github.com/openrewrite/rewrite-testing-frameworks/blob/30f35fe919b8166c19ddf22e2f1ea1c0d918487a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java#L125-L138

Your exact example might already work if the name of the static imported method matches the renamed test; but with a few small adjustments I'm sure we can find a way to fail and then fix the issue.