Skip to content

Commit

Permalink
[640] - check for junit4 mockito runners to add mockito-junit-jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
promanenko committed Jan 28, 2025
1 parent 65c88ad commit d8df82d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ tags:
- junit
- mockito
recipeList:
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.mockito
artifactId: mockito-junit-jupiter
version: 4.x
onlyIfUsing: org.mockito..MockitoJUnit*Runner
acceptTransitive: true
scope: test
- org.openrewrite.java.testing.mockito.Mockito1to4Migration
- org.openrewrite.java.testing.mockito.MockitoJUnitRunnerSilentToExtension
- org.openrewrite.java.testing.junit5.RunnerToExtension:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;

@SuppressWarnings({"NewClassNamingConvention", "EqualsWithItself", "deprecation", "LanguageMismatch"})
Expand All @@ -40,7 +40,7 @@ class JUnit5MigrationTest implements RewriteTest {
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2"))
.classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2", "mockito-all-1.10"))
.recipe(Environment.builder()
.scanRuntimeClasspath("org.openrewrite.java.testing.junit5")
.build()
Expand Down Expand Up @@ -440,4 +440,78 @@ void bumpSurefireOnOlderMavenVersions() {
)
);
}

@Test
void addMockitoJupiterDependencyIfExtendWithPresent() {
rewriteRun(
mavenProject("sample",
//language=java
srcMainJava(
java(
"""
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {}
""",
"""
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class MyClassTest {}
"""
)
),
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>project</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>project</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
"""
)
)
);
}
}

0 comments on commit d8df82d

Please sign in to comment.