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

Only upgrade maven-surefire-plugin on older Maven versions #517

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,7 @@ recipeList:
pluginArtifactId: maven-surefire-plugin
groupId: org.apache.maven.surefire
artifactId: surefire-junit*
- org.openrewrite.maven.AddPlugin:
groupId: org.apache.maven.plugins
artifactId: maven-surefire-plugin
version: 3.2.5
- org.openrewrite.maven.AddPluginDependency:
pluginGroupId: org.apache.maven.plugins
pluginArtifactId: maven-surefire-plugin
groupId: org.junit.platform
artifactId: junit-platform-surefire-provider
version: 1.1.0
- org.openrewrite.java.testing.junit5.UpgradeSurefirePlugin
- org.openrewrite.java.testing.junit5.UseHamcrestAssertThat
- org.openrewrite.java.testing.junit5.MigrateAssumptions
- org.openrewrite.java.testing.junit5.UseMockitoExtension
Expand Down Expand Up @@ -317,3 +308,24 @@ recipeList:
newGroupId: org.xmlunit
newArtifactId: xmlunit-legacy
newVersion: 2.x
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.junit5.UpgradeSurefirePlugin
displayName: Upgrade Surefire Plugin
description: Upgrades the Maven Surefire Plugin to the latest version if still using an older Maven version.
preconditions:
- org.openrewrite.java.search.HasBuildToolVersion:
type: Maven
version: 0.0.1-3.5.4
recipeList:
- org.openrewrite.maven.AddPlugin:
groupId: org.apache.maven.plugins
artifactId: maven-surefire-plugin
version: 3.2.5
- org.openrewrite.maven.AddPluginDependency:
pluginGroupId: org.apache.maven.plugins
pluginArtifactId: maven-surefire-plugin
groupId: org.junit.platform
artifactId: junit-platform-surefire-provider
version: 1.1.0

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
package org.openrewrite.java.testing.junit5;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.Tree;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.marker.BuildTool;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -74,6 +75,7 @@ void method() {
);
}

@DocumentExample
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/145")
void assertThatReceiver() {
Expand Down Expand Up @@ -170,22 +172,6 @@ void dontExcludeJunit4DependencyfromTestcontainers() {
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
""";
// Output identical, but we want to make sure we don't exclude junit4 from testcontainers
Expand Down Expand Up @@ -229,22 +215,6 @@ void dontExcludeJunit4DependencyfromSpringBootTestcontainers() {
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
""";
// Output identical, but we want to make sure we don't exclude junit4 from testcontainers
Expand Down Expand Up @@ -343,7 +313,7 @@ public void test() {
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class A extends AbstractTest {
@BeforeEach
public void before() {
Expand All @@ -368,54 +338,82 @@ void noJunitDependencyIfApiAlreadyPresent() {
spec -> spec.beforeRecipe(withToolingApi()),
//language=groovy
buildGradle(
"""
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
"""),
"""
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
"""),
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>dev.ted</groupId>
<artifactId>testcontainer-migrate</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
""")
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>dev.ted</groupId>
<artifactId>testcontainer-migrate</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""")
);
}

@Test
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
void bumpSurefireOnOlderMavenVersions() {
rewriteRun(
spec -> spec.recipeFromResource("/META-INF/rewrite/junit5.yml", "org.openrewrite.java.testing.junit5.UpgradeSurefirePlugin"),
pomXml(
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>dev.ted</groupId>
<artifactId>testcontainer-migrate</artifactId>
<version>0.0.1</version>
</project>
""",
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>dev.ted</groupId>
<artifactId>testcontainer-migrate</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
""",
spec -> spec.markers(new BuildTool(Tree.randomId(), BuildTool.Type.Maven, "3.5.4"))
)
);
}
}