Refaster rules that replace TestNG APIs with AssertJ equivalents

Apache 2.0

Some of the classes below have TestNG @BeforeTemplates that reference wildcard type bounds (<?>), while the associated AssertJ @AfterTemplates reference stricter type bounds. This introduces the risk of producing invalid code. We do this anyway, because TestNG's wildcard types can cause javac to infer less specific types than AssertJ requires, while the appropriate (more specific) types will be inferred properly when plugged into AssertJ's API.

The following is an example of a TestNG statement, which would not be rewritten if it weren't for the wildcard matching (note that the type parameters of the map on the right-hand side will be inferred to be <Object, Object> rather than <String, Object>).

List<Map<String, Object>> myMaps = new ArrayList<>();
assertEquals(myMaps, ImmutableList.of(ImmutableMap.of()));

Warning: while both libraries throw an AssertionError in case of an assertion failure, the exact subtype used generally differs. Source.

tech.picnic.errorprone.refasterrules.TestNGToAssertJRulesRecipes
mod run . --recipe=tech.picnic.errorprone.refasterrules.TestNGToAssertJRulesRecipes

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. Refaster template TestNGToAssertJRules.Fail
  2. Refaster template TestNGToAssertJRules.FailWithString
  3. Refaster template TestNGToAssertJRules.FailWithStringAndThrowable
  4. Refaster template TestNGToAssertJRules.AssertThatIsTrue
  5. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsTrue
  6. Refaster template TestNGToAssertJRules.AssertThatIsFalse
  7. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsFalse
  8. Refaster template TestNGToAssertJRules.AssertThatIsNull
  9. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNull
  10. Refaster template TestNGToAssertJRules.AssertThatIsNotNull
  11. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNotNull
  12. Refaster template TestNGToAssertJRules.AssertThatIsSameAs
  13. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsSameAs
  14. Refaster template TestNGToAssertJRules.AssertThatIsNotSameAs
  15. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNotSameAs
  16. Refaster template TestNGToAssertJRules.AssertThatIsEqualTo
  17. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsEqualTo
  18. Refaster template TestNGToAssertJRules.AssertThatIsCloseToOffsetFloat
  19. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsCloseToOffsetFloat
  20. Refaster template TestNGToAssertJRules.AssertThatIsCloseToOffsetDouble
  21. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsCloseToOffsetDouble
  22. Refaster template TestNGToAssertJRules.AssertThatContainsExactly
  23. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageContainsExactly
  24. Refaster template TestNGToAssertJRules.AssertThatContainsExactlyOffsetFloat
  25. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyOffsetFloat
  26. Refaster template TestNGToAssertJRules.AssertThatContainsExactlyOffsetDouble
  27. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyOffsetDouble
  28. Refaster template TestNGToAssertJRules.AssertThatContainsExactlyInAnyOrder
  29. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyInAnyOrder
  30. Refaster template TestNGToAssertJRules.AssertThatToIterableContainsExactlyElementsOfImmutableListCopyOf
  31. Refaster template TestNGToAssertJRules.AssertThatToIterableWithFailMessageContainsExactlyElementsOfImmutableListCopyOf
  32. Refaster template TestNGToAssertJRules.AssertThatContainsExactlyElementsOf
  33. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyElementsOf
  34. Refaster template TestNGToAssertJRules.AssertThatHasSameElementsAs
  35. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageHasSameElementsAs
  36. Refaster template TestNGToAssertJRules.AssertThatIsNotEqualTo
  37. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNotEqualTo
  38. Refaster template TestNGToAssertJRules.AssertThatIsNotCloseToOffsetFloat
  39. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNotCloseToOffsetFloat
  40. Refaster template TestNGToAssertJRules.AssertThatIsNotCloseToOffsetDouble
  41. Refaster template TestNGToAssertJRules.AssertThatWithFailMessageIsNotCloseToOffsetDouble