Migrate System Rules to System Stubs and JUnit Pioneer
org.openrewrite.java.testing.junit5.MigrateSystemRulesArtifactorg.openrewrite.recipe:rewrite-testing-frameworksMigrates the JUnit 4 rules of System Rules (com.github.stefanbirkner:system-rules) as part of the JUnit 4 to 5 migration. System property rules that only take string literals become JUnit Pioneer annotations; the other system property, environment variable, standard stream and standard input rules become System Stubs @SystemStub fields, and ExpectedSystemExit becomes System Stubs' catchSystemExit(..). Rules that can not be migrated get a TODO comment, and System Rules is only removed once nothing uses it.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.testing.junit5.MigrateSystemRules")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.49.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.testing.junit5.MigrateSystemRulesIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-testing-frameworks:RELEASEDefinition
This recipe runs the following recipes in order.
- Migrate JUnit 4 environmentVariables rule to JUnit 5 system stubs extension
org.openrewrite.java.testing.junit5.EnvironmentVariables - Migrate System Rules system property rules to JUnit Pioneer annotations
org.openrewrite.java.testing.junit5.SystemPropertyRulesToPioneer - Migrate System Rules to System Stubs
org.openrewrite.java.testing.junit5.SystemRulesToSystemStubs - Migrate System Rules
ExpectedSystemExitto System StubscatchSystemExit(..)org.openrewrite.java.testing.junit5.ExpectedSystemExitToCatchSystemExit - Update dependencies for the System Rules migration
org.openrewrite.java.testing.junit5.SystemRulesDependencies
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats