Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ExtendWith(SpringExtension.class) is added twice when class contains @SpringClassRule #621

Open
FieteO opened this issue Nov 8, 2024 · 1 comment
Labels
bug Something isn't working question Further information is requested

Comments

@FieteO
Copy link
Contributor

FieteO commented Nov 8, 2024

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v5.22.0

How are you running OpenRewrite?

I am using the command line invocation:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration -Drewrite.exportDatatables=true

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

import org.junit.ClassRule;
import org.junit.Rule;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;

public class MyTest {

        @ClassRule
        public static final SpringClassRule springClassRule = new SpringClassRule();

        @Rule
        public final SpringMethodRule springMethodRule = new SpringMethodRule();

}

What did you expect to see?

import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
public class MyTest {

}

What did you see instead?

The @ExtendWith() annotation is added twice and the org.springframework.test.context.junit.jupiter.SpringExtension import is missing.

import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(SpringExtension.class)
@ExtendWith(SpringExtension.class)
public class MyTest {

}

Are you interested in contributing a fix to OpenRewrite?

No

@FieteO FieteO added the bug Something isn't working label Nov 8, 2024
@FieteO FieteO changed the title @ExtendWith(SpringExtension.class) is added twice when class contains @ @ExtendWith(SpringExtension.class) is added twice when class contains @SpringClassRule Nov 8, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Nov 11, 2024
@timtebeek
Copy link
Contributor

Hi @FieteO ; We have a test cas e that's nearly identical to what you have reported that passes:

@Test
void migrateAndAddSpringExtension() {
rewriteRun(
//language=java
java(
"""
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.junit.ClassRule;
import org.junit.Rule;
class SomeTest {
@ClassRule
public static final SpringClassRule springClassRule = new SpringClassRule();
@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
}
""",
"""
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
class SomeTest {
}
"""
)
);
}

Would you mind altering that test to match your case and make it fail? Because right now this can not be replicated.

@timtebeek timtebeek added the question Further information is requested label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
Status: Backlog
Development

No branches or pull requests

2 participants