Recipe testing best practices
Recipe ID
org.openrewrite.java.recipes.RecipeTestingBestPracticesArtifactorg.openrewrite.recipe:rewrite-rewriteBest practices for testing recipes.
Composite recipeMSAL
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.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.recipes.RecipeTestingBestPractices")
}
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-rewrite:0.33.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.recipes.RecipeTestingBestPracticesIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-rewrite:RELEASEDefinition
This recipe runs the following recipes in order.
- Replace
Stream.collect(Collectors.toUnmodifiableList())withStream.toList()org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList - One classpath argument per line
org.openrewrite.java.recipes.ClasspathArgumentsOnePerLine - RewriteTest classes should not be public
org.openrewrite.java.recipes.RewriteTestClassesShouldNotBePublic - Automatically select recipe examples from the unit test cases of a recipe
org.openrewrite.java.recipes.SelectRecipeExamples - Single
@DocumentExampleper test classorg.openrewrite.java.recipes.SingleDocumentExample - Show
@DocumentExamples firstorg.openrewrite.java.recipes.ReorderTestMethods - Replace null with RewriteTest.doesNotExist()
org.openrewrite.java.recipes.ReplaceNullWithDoesNotExist - New line at the end of
SourceSpecstext blocksorg.openrewrite.java.recipes.SourceSpecTextBlockNewLine - Minimal indentation for
SourceSpecstext blocksorg.openrewrite.java.recipes.SourceSpecTextBlockIndentation - Refactor RewriteTest to use defaults method
org.openrewrite.java.recipes.UseRewriteTestDefaults - Use
StringUtilsutility methodsorg.openrewrite.java.recipes.UseStringUtilsRecipes - Use
varfor variables initialized with type castsorg.openrewrite.java.migrate.lang.var.UseVarForTypeCast - Use
varfor constructor call assignmentsorg.openrewrite.java.migrate.lang.var.UseVarForConstructors - Apply
varto Generic Constructorsorg.openrewrite.java.migrate.lang.var.UseVarForGenericsConstructors - Apply
varto generic method invocationsorg.openrewrite.java.migrate.lang.var.UseVarForGenericMethodInvocations - Use
varfor primitive and String variablesorg.openrewrite.java.migrate.lang.var.UseVarForPrimitive - Use modernized
java.utilAPIsorg.openrewrite.java.migrate.util.JavaUtilAPIs - Convert Javadoc to Markdown documentation comments
org.openrewrite.java.migrate.lang.JavadocToMarkdownDocComment - JUnit 6 best practices
org.openrewrite.java.testing.junit.JUnit6BestPractices - AssertJ best practices
org.openrewrite.java.testing.assertj.Assertj - Fix missing braces
org.openrewrite.staticanalysis.NeedBraces - Remove
System.out#printlnstatementsorg.openrewrite.staticanalysis.RemoveSystemOutPrintln - Reorder annotations alphabetically
org.openrewrite.staticanalysis.ReorderAnnotations - Use static import
org.openrewrite..Assertions *(..)org.openrewrite.java.UseStaticImport - Use static import
org.openrewrite.test.RewriteTest *(..)org.openrewrite.java.UseStaticImport - Use static import
org.openrewrite.test.SourceSpecs *(..)org.openrewrite.java.UseStaticImport - Change method target to static
org.openrewrite.java.ChangeMethodTargetToStatic - Change method name
java.util.List asList(..)tooforg.openrewrite.java.ChangeMethodName
Data tables
Structured output this recipe can produce.
- Maven metadata failuresAttempts to resolve maven metadata that failed.
org.openrewrite.maven.table.MavenMetadataFailures - 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