Class AddAxonTestFixtureTearDown

java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.AddAxonTestFixtureTearDown
All Implemented Interfaces:
Cloneable

public class AddAxonTestFixtureTearDown extends org.openrewrite.Recipe
Adds @AfterEach void tearDown() { <fixture>.stop(); } to test classes that declare a field of type AxonTestFixture but have no existing @AfterEach (and no method already named tearDown). Pairs with MigrateAggregateTestFixtureSetup which produces the field; the tear-down step was previously left for manual migration.

Why automate it: every AxonTestFixture owns lifecycle resources (configurer + entity registrations + lifecycle-managed components). Without stop() between tests the resources leak across test methods, which surfaces as flaky / cross-test interference under faster reruns. Generating the @AfterEach consistently is safer than relying on each test author to remember.

The recipe is conservative:

  • Requires at least one method annotated @BeforeEach on the same class. A class that needs @AfterEach cleanup almost always already has @BeforeEach setup; demanding the counterpart filters out non-JUnit-5 classes (and the recipe-test toy fixtures that are not real test classes) without requiring resolved annotation types.
  • Skips when the class already has any method annotated with @AfterEach — the user's cleanup might already invoke stop() or might be intentionally orthogonal; either way, silently appending a sibling could clash.
  • Skips when the class already has a method named tearDown (regardless of annotation) — avoids generating a duplicate method that would not compile.
  • Java sources only. Kotlin sources fall through to a no-op so call sites compile; Kotlin support is left for a sibling recipe using KotlinTemplate, mirroring MigrateAggregateTestFixtureSetup.

When to run: after ChangeType AggregateTestFixture → AxonTestFixture, so the field type already carries the AF5 FQN that this recipe matches. Idempotent on re-runs: a second pass detects the just-inserted @AfterEach and skips.

Since:
5.1.1
Author:
Mateusz Nowak
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.openrewrite.Recipe

    org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe
  • Field Summary

    Fields inherited from class org.openrewrite.Recipe

    contributors, examples, PANIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext>
     

    Methods inherited from class org.openrewrite.Recipe

    addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AddAxonTestFixtureTearDown

      public AddAxonTestFixtureTearDown()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in class org.openrewrite.Recipe
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe