Package org.axonframework.migration
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
@BeforeEachon the same class. A class that needs@AfterEachcleanup almost always already has@BeforeEachsetup; 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 invokestop()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, mirroringMigrateAggregateTestFixtureSetup.
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 -
Method Summary
Modifier and TypeMethodDescriptionorg.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
-
Constructor Details
-
AddAxonTestFixtureTearDown
public AddAxonTestFixtureTearDown()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()- Overrides:
getVisitorin classorg.openrewrite.Recipe
-