@ExtendWith(SpringExtension.class) is added twice when class contains @SpringClassRule
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
Hi @FieteO ; We have a test cas e that's nearly identical to what you have reported that passes: https://github.com/openrewrite/rewrite-spring/blob/729164fd713cbd0bfce44e582b0d613f4d1965b0/src/test/java/org/openrewrite/java/spring/test/SpringRulesToJUnitExtensionTest.java#L104-L136
Would you mind altering that test to match your case and make it fail? Because right now this can not be replicated.
Closing as the linked test passes, and we've not heard what's needed to reproduce the issue since.