AssertJ best practices
Recipe ID
org.openrewrite.java.testing.assertj.AssertjArtifact
org.openrewrite.recipe:rewrite-testing-frameworksMigrates JUnit asserts to AssertJ and applies best practices to assertions.
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.assertj.AssertjIf 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.
- Change type
org.openrewrite.java.ChangeType - Change type
org.openrewrite.java.ChangeType - Change type
org.openrewrite.java.ChangeType - Migrate Hamcrest assertions to AssertJ
org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ - Migrate Google Truth to AssertJ
org.openrewrite.java.testing.truth.MigrateTruthToAssertJ - Migrate Fest 2.x to AssertJ
org.openrewrite.java.testing.assertj.FestToAssertj - Migrate JUnit asserts to AssertJ
org.openrewrite.java.testing.assertj.JUnitToAssertj - Migrate TestNG assertions to AssertJ
org.openrewrite.java.testing.testng.TestNgToAssertj - Adopt AssertJ Duration assertions
org.openrewrite.java.testing.assertj.AdoptAssertJDurationAssertions - Replace
AbstractDateAssert#isEqualToIgnoringMillis(java.util.Date)byby isCloseTo(Date, long)org.openrewrite.java.testing.assertj.IsEqualToIgnoringMillisToIsCloseToRecipe - Decompose
assertThaton conjunctions into separate assertionsorg.openrewrite.java.testing.assertj.DecomposeConjunctionAssertion - Simplify AssertJ chained assertions
org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions - Shorten AssertJ assertions
org.openrewrite.java.testing.assertj.SimplifyAssertJAssertions - Simplify AssertJ assertions on
instanceofexpressionsorg.openrewrite.java.testing.assertj.SimplifyAssertJInstanceOfAssertion - Simplify AssertJ assertions on
==and!=comparisonsorg.openrewrite.java.testing.assertj.SimplifyAssertJEqualityAssertion - Simplify AssertJ assertions with
hasSizeargumentorg.openrewrite.java.testing.assertj.SimplifyHasSizeAssertion - Simplify literal-first AssertJ size assertions to
hasSizeorg.openrewrite.java.testing.assertj.SimplifyHasSizeFromIsEqualToAssertion - Simplify AssertJ assertions on an array's
lengthorg.openrewrite.java.testing.assertj.SimplifyArrayLengthAssertion - Simplify AssertJ assertions on SequencedCollection
org.openrewrite.java.testing.assertj.SimplifySequencedCollectionAssertions - Simplify
assertThat(collection.stream().map(...))toassertThat(collection).extracting(...)org.openrewrite.java.testing.assertj.SimplifyStreamMapToExtracting - Refaster rules related to AssertJ assertions over
BigDecimalstech.picnic.errorprone.refasterrules.AssertJBigDecimalRulesRecipes - Adopt AssertJ BigInteger Assertions
org.openrewrite.java.testing.assertj.AssertJBigIntegerRulesRecipes AssertJBooleanRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJBooleanRulesRecipes- Adopt AssertJ Byte Assertions
org.openrewrite.java.testing.assertj.AssertJByteRulesRecipes AssertJCharSequenceRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJCharSequenceRulesRecipesAssertJComparableRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJComparableRulesRecipes- Adopt AssertJ Double Assertions
org.openrewrite.java.testing.assertj.AssertJDoubleRulesRecipes AssertJEnumerableRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJEnumerableRulesRecipesAssertJDurationRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJDurationRulesRecipes- Adopt AssertJ Float Assertions
org.openrewrite.java.testing.assertj.AssertJFloatRulesRecipes AssertJInstantRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJInstantRulesRecipes- Adopt AssertJ Integer Assertions
org.openrewrite.java.testing.assertj.AssertJIntegerRulesRecipes AssertJIterableRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJIterableRulesRecipesAssertJIteratorRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJIteratorRulesRecipes- Adopt AssertJ Long Assertions
org.openrewrite.java.testing.assertj.AssertJLongRulesRecipes AssertJMapRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJMapRulesRecipesAssertJNumberRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJNumberRulesRecipesAssertJObjectRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJObjectRulesRecipesAssertJOptionalRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJOptionalRulesRecipesAssertJPathRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJPathRulesRecipes- Adopt AssertJ Short Assertions
org.openrewrite.java.testing.assertj.AssertJShortRulesRecipes AssertJPrimitiveRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJPrimitiveRulesRecipesAssertJRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJRulesRecipesAssertJStringRulesRefaster recipestech.picnic.errorprone.refasterrules.AssertJStringRulesRecipes- Refaster rules related to AssertJ assertions over expressions that may throw a
Throwablesubtypetech.picnic.errorprone.refasterrules.AssertJThrowingCallableRulesRecipes - Collapse consecutive
assertThatstatementsorg.openrewrite.java.testing.assertj.CollapseConsecutiveAssertThatStatements - Collapse
assertThatfollowed byreturninto single statementorg.openrewrite.java.testing.assertj.ReturnActual - Simplify redundant AssertJ assertion chains
org.openrewrite.java.testing.assertj.SimplifyRedundantAssertJChains - Migrate
AssertionsForClassTypesandAssertionsForInterfaceTypestoAssertionsorg.openrewrite.java.testing.assertj.MigrateAssertionsForClassAndInterfaceTypes - Statically import AssertJ's
assertThatorg.openrewrite.java.testing.assertj.StaticImports
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