AssertJ best practices

MSAL

Migrates JUnit asserts to AssertJ and applies best practices to assertions.

org.openrewrite.java.testing.assertj.Assertj
mod run . --recipe=org.openrewrite.java.testing.assertj.Assertj

Install 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.

  1. Change type org.assertj.core.annotations.Beta to org.assertj.core.annotation.Beta
  2. Change type org.assertj.core.util.CanIgnoreReturnValue to org.assertj.core.annotation.CanIgnoreReturnValue
  3. Change type org.assertj.core.util.CheckReturnValue to org.assertj.core.annotation.CheckReturnValue
  4. Migrate Hamcrest assertions to AssertJ
  5. Migrate Google Truth to AssertJ
  6. Migrate Fest 2.x to AssertJ
  7. Migrate JUnit asserts to AssertJ
  8. Migrate TestNG assertions to AssertJ
  9. Adopt AssertJ Duration assertions
  10. Replace AbstractDateAssert#isEqualToIgnoringMillis(java.util.Date) with isCloseTo(Date, long)
  11. Decompose assertThat on conjunctions into separate assertions
  12. Simplify AssertJ chained assertions
  13. Shorten AssertJ assertions
  14. Simplify AssertJ assertions on instanceof expressions
  15. Simplify AssertJ assertions on == and != comparisons
  16. Simplify AssertJ assertions with hasSize argument
  17. Simplify literal-first AssertJ size assertions to hasSize
  18. Simplify AssertJ assertions on an array's length
  19. Simplify AssertJ assertions on SequencedCollection
  20. Simplify assertThat(collection.stream().map(...)) to assertThat(collection).extracting(...)
  21. Refaster rules related to AssertJ assertions over BigDecimals
  22. Adopt AssertJ BigInteger assertions
  23. AssertJBooleanRules Refaster recipes
  24. Adopt AssertJ Byte assertions
  25. AssertJCharSequenceRules Refaster recipes
  26. AssertJComparableRules Refaster recipes
  27. Adopt AssertJ Double assertions
  28. AssertJEnumerableRules Refaster recipes
  29. AssertJDurationRules Refaster recipes
  30. Adopt AssertJ Float assertions
  31. AssertJInstantRules Refaster recipes
  32. Adopt AssertJ Integer assertions
  33. AssertJIterableRules Refaster recipes
  34. AssertJIteratorRules Refaster recipes
  35. Adopt AssertJ Long assertions
  36. AssertJMapRules Refaster recipes
  37. AssertJNumberRules Refaster recipes
  38. AssertJObjectRules Refaster recipes
  39. AssertJOptionalRules Refaster recipes
  40. AssertJPathRules Refaster recipes
  41. Adopt AssertJ Short assertions
  42. AssertJPrimitiveRules Refaster recipes
  43. AssertJRules Refaster recipes
  44. AssertJStringRules Refaster recipes
  45. Refaster rules related to AssertJ assertions over expressions that may throw a Throwable subtype
  46. Collapse consecutive assertThat statements
  47. Collapse a captured exception and its assertThat into assertThatThrownBy
  48. Collapse assertThat followed by return into single statement
  49. Simplify redundant AssertJ assertion chains
  50. Place AssertJ descriptions and failure messages before the assertion
  51. Migrate AssertionsForClassTypes and AssertionsForInterfaceTypes to Assertions
  52. Statically import AssertJ's assertThat