Clean Up Assertions
Recipe ID
org.openrewrite.java.testing.junit5.CleanupAssertionsArtifact
org.openrewrite.recipe:rewrite-testing-frameworksSimplifies JUnit Jupiter assertions to their most-direct equivalents.
Usage
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.CleanupAssertionsIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-testing-frameworks:3.43.0Definition
This recipe runs the following recipes in order.
- Replace JUnit
assertTrue(!<boolean>)toassertFalse(<boolean>)org.openrewrite.java.testing.cleanup.AssertTrueNegationToAssertFalse - Replace JUnit
assertFalse(!<boolean>)toassertTrue(<boolean>)org.openrewrite.java.testing.cleanup.AssertFalseNegationToAssertTrue - Replace JUnit
assertTrue(a.equals(b))toassertEquals(a,b)org.openrewrite.java.testing.cleanup.AssertTrueEqualsToAssertEquals - Junit
assertTrue(a == b)toassertEquals(a,b)org.openrewrite.java.testing.cleanup.AssertTrueComparisonToAssertEquals - Replace JUnit
assertFalse(a.equals(b))toassertNotEquals(a,b)org.openrewrite.java.testing.cleanup.AssertFalseEqualsToAssertNotEquals assertEquals(a, null)toassertNull(a)org.openrewrite.java.testing.cleanup.AssertEqualsNullToAssertNull- Replace JUnit
assertFalse(a == null)toassertNotNull(a)org.openrewrite.java.testing.cleanup.AssertFalseNullToAssertNotNull - Replace JUnit
assertTrue(a == null)toassertNull(a)org.openrewrite.java.testing.cleanup.AssertTrueNullToAssertNull - Replace JUnit
assertEquals(false, <boolean>)toassertFalse(<boolean>)/assertTrue(<boolean>)org.openrewrite.java.testing.cleanup.AssertEqualsBooleanToAssertBoolean - Replace JUnit
assertNotEquals(false, <boolean>)toassertFalse(<boolean>)/assertTrue(<boolean>)org.openrewrite.java.testing.cleanup.AssertNotEqualsBooleanToAssertBoolean - Assertion arguments should be passed in the correct order
org.openrewrite.java.testing.cleanup.AssertionsArgumentOrder
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