Refaster rules that replace TestNG APIs with AssertJ equivalents
Apache 2.0Some 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. TestNGToAssertJRulesRecipesmod run . --recipe= tech. picnic. errorprone. refasterrules. TestNGToAssertJRulesRecipesInstall 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.
- Refaster template
TestNGToAssertJRules.Fail - Refaster template
TestNGToAssertJRules.FailWithString - Refaster template
TestNGToAssertJRules.FailWithStringAndThrowable - Refaster template
TestNGToAssertJRules.AssertThatIsTrue - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsTrue - Refaster template
TestNGToAssertJRules.AssertThatIsFalse - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsFalse - Refaster template
TestNGToAssertJRules.AssertThatIsNull - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNull - Refaster template
TestNGToAssertJRules.AssertThatIsNotNull - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNotNull - Refaster template
TestNGToAssertJRules.AssertThatIsSameAs - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsSameAs - Refaster template
TestNGToAssertJRules.AssertThatIsNotSameAs - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNotSameAs - Refaster template
TestNGToAssertJRules.AssertThatIsEqualTo - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsEqualTo - Refaster template
TestNGToAssertJRules.AssertThatIsCloseToOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsCloseToOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatIsCloseToOffsetDouble - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsCloseToOffsetDouble - Refaster template
TestNGToAssertJRules.AssertThatContainsExactly - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageContainsExactly - Refaster template
TestNGToAssertJRules.AssertThatContainsExactlyOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatContainsExactlyOffsetDouble - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyOffsetDouble - Refaster template
TestNGToAssertJRules.AssertThatContainsExactlyInAnyOrder - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyInAnyOrder - Refaster template
TestNGToAssertJRules.AssertThatToIterableContainsExactlyElementsOfImmutableListCopyOf - Refaster template
TestNGToAssertJRules.AssertThatToIterableWithFailMessageContainsExactlyElementsOfImmutableListCopyOf - Refaster template
TestNGToAssertJRules.AssertThatContainsExactlyElementsOf - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageContainsExactlyElementsOf - Refaster template
TestNGToAssertJRules.AssertThatHasSameElementsAs - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageHasSameElementsAs - Refaster template
TestNGToAssertJRules.AssertThatIsNotEqualTo - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNotEqualTo - Refaster template
TestNGToAssertJRules.AssertThatIsNotCloseToOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNotCloseToOffsetFloat - Refaster template
TestNGToAssertJRules.AssertThatIsNotCloseToOffsetDouble - Refaster template
TestNGToAssertJRules.AssertThatWithFailMessageIsNotCloseToOffsetDouble