AssertJ best practices
MSALMigrates JUnit asserts to AssertJ and applies best practices to assertions.
org. openrewrite. java. testing. assertj. Assertjmod run . --recipe= org. openrewrite. java. testing. assertj. AssertjInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Change type
org.assertj.core.annotations.Betatoorg.assertj.core.annotation.Beta - Change type
org.assertj.core.util.CanIgnoreReturnValuetoorg.assertj.core.annotation.CanIgnoreReturnValue - Change type
org.assertj.core.util.CheckReturnValuetoorg.assertj.core.annotation.CheckReturnValue - Migrate Hamcrest assertions to AssertJ
- Migrate Google Truth to AssertJ
- Migrate Fest 2.x to AssertJ
- Migrate JUnit asserts to AssertJ
- Migrate TestNG assertions to AssertJ
- Adopt AssertJ Duration assertions
- Replace
AbstractDateAssert#isEqualToIgnoringMillis(java.util.Date)withisCloseTo(Date, long) - Decompose
assertThaton conjunctions into separate assertions - Simplify AssertJ chained assertions
- Shorten AssertJ assertions
- Simplify AssertJ assertions on
instanceofexpressions - Simplify AssertJ assertions on
==and!=comparisons - Simplify AssertJ assertions with
hasSizeargument - Simplify literal-first AssertJ size assertions to
hasSize - Simplify AssertJ assertions on an array's
length - Simplify AssertJ assertions on
SequencedCollection - Simplify
assertThat(collection.stream().map(...))toassertThat(collection).extracting(...) - Refaster rules related to AssertJ assertions over
BigDecimals - Adopt AssertJ
BigIntegerassertions AssertJBooleanRulesRefaster recipes- Adopt AssertJ
Byteassertions AssertJCharSequenceRulesRefaster recipesAssertJComparableRulesRefaster recipes- Adopt AssertJ
Doubleassertions AssertJEnumerableRulesRefaster recipesAssertJDurationRulesRefaster recipes- Adopt AssertJ
Floatassertions AssertJInstantRulesRefaster recipes- Adopt AssertJ
Integerassertions AssertJIterableRulesRefaster recipesAssertJIteratorRulesRefaster recipes- Adopt AssertJ
Longassertions AssertJMapRulesRefaster recipesAssertJNumberRulesRefaster recipesAssertJObjectRulesRefaster recipesAssertJOptionalRulesRefaster recipesAssertJPathRulesRefaster recipes- Adopt AssertJ
Shortassertions AssertJPrimitiveRulesRefaster recipesAssertJRulesRefaster recipesAssertJStringRulesRefaster recipes- Refaster rules related to AssertJ assertions over expressions that may throw a
Throwablesubtype - Collapse consecutive
assertThatstatements - Collapse a captured exception and its
assertThatintoassertThatThrownBy - Collapse
assertThatfollowed byreturninto single statement - Simplify redundant AssertJ assertion chains
- Place AssertJ descriptions and failure messages before the assertion
- Migrate
AssertionsForClassTypesandAssertionsForInterfaceTypestoAssertions - Statically import AssertJ's
assertThat