← All recipes
Open source

Refaster rules that replace TestNG APIs with AssertJ equivalents

Recipe IDtech.picnic.errorprone.refasterrules.TestNGToAssertJRulesRecipes
Artifactorg.openrewrite.recipe:rewrite-third-party

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>). ``java List<Map<String, Object>> myMaps = new ArrayList<>(); assertEquals(myMaps, ImmutableList.of(ImmutableMap.of())); <strong>Warning:</strong> while both libraries throw an AssertionError` in case of an assertion failure, the exact subtype used generally differs. Source.

Composite recipeApache 2.0

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

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

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-third-party:0.44.0

Definition

This recipe runs the following recipes in order.

Data tables

Structured output this recipe can produce.

  • 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