rewrite-spring icon indicating copy to clipboard operation
rewrite-spring copied to clipboard

Replace @MockBean and @SpyBean recipe incorrectly migrates @MockBeans({@MockBean(class)}

Open NickGotv opened this issue 9 months ago • 1 comments

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v6.3.2
  • Maven/Gradle plugin v6.3.2
  • rewrite-spring v6.3.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a multiple module project.

<build>
        <plugins>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>6.3.2</version>
                <configuration>
                    <exportDatatables>true</exportDatatables>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.spring.boot3.ReplaceMockBeanAndSpyBean</recipe>
                    </activeRecipes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-spring</artifactId>
                        <version>6.3.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

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

have any JUNIT test with the following structure

@MockBeans({@MockBean(ClassA.class), @MockBean(ClassB.class)})
class SomeTest {
}

What did you expect to see?

@MockitoBean(types = {ClassA.class, ClassB.class})
class SomeTest {
}

or

@MockitoBeans(@MockitoBean(types = ClassA.class), @MockitoBean(types =ClassB.class)})
class SomeTest {
}

What did you see instead?

@MockBeans({@MockitoBean, @MockitoBean})
class SomeTest {
}

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

none for the test with this issue

Are you interested in [contributing a fix to OpenRewrite]

not at the moment

NickGotv avatar Mar 28 '25 10:03 NickGotv

Thanks for the report! Seems indeed like we should ensure we handle annotations nested as annotations arguments correctly.

timtebeek avatar Mar 28 '25 13:03 timtebeek