Skip to content

Commit

Permalink
Invoke TestInstancePreDestroyCallbacks in reverse registration order
Browse files Browse the repository at this point in the history
Prior to this commit, when using PER_CLASS test instance lifecycle
semantics, TestInstancePreDestroyCallback extensions were invoked in
the order in which they were registered, which violates the general
"wrapping" principle for extensions invoked after a container or test.

This commit fixes this by invoking TestInstancePreDestroyCallback
extensions in reverse registration order when PER_CLASS test instance
lifecycle semantics have been configured.

Fixes #2209
  • Loading branch information
sbrannen committed Mar 12, 2020
1 parent ecae6ee commit e5985c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ on GitHub.

==== Bug Fixes

* ❓
* `TestInstancePreDestroyCallback` extensions are now invoked in reverse registration
order when `PER_CLASS` test instance lifecycle semantics have been configured.

==== Deprecations and Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private void invokeTestInstancePreDestroyCallbacks(JupiterEngineExecutionContext
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();

context.getExtensionRegistry().stream(TestInstancePreDestroyCallback.class).forEach(
context.getExtensionRegistry().getReversedExtensions(TestInstancePreDestroyCallback.class).forEach(
extension -> throwableCollector.execute(() -> extension.preDestroyTestInstance(extensionContext)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void instancePreDestroyCallbacksInNestedClasses() {
"beforeOuterMethod",
"beforeInnerMethod",
"testInner",
"bazPreDestroyCallbackTestInstance:InnerTestCase",
"barPreDestroyCallbackTestInstance:InnerTestCase",
"fooPreDestroyCallbackTestInstance:InnerTestCase"
);
Expand All @@ -77,7 +78,7 @@ void testSpecificTestInstancePreDestroyCallbackIsCalled() {

@Test
void classLifecyclePreDestroyCallbacks() {
executeTestsForClass(PerClassLifecyclePreDestroyCallbackWithTwoTestMethods.class).testEvents()//
executeTestsForClass(PerClassLifecyclePreDestroyCallbacksWithTwoTestMethods.class).testEvents()//
.assertStatistics(stats -> stats.started(2).succeeded(2));

// @formatter:off
Expand All @@ -86,7 +87,8 @@ void classLifecyclePreDestroyCallbacks() {
"test1",
"beforeEachMethod",
"test2",
"fooPreDestroyCallbackTestInstance:PerClassLifecyclePreDestroyCallbackWithTwoTestMethods"
"barPreDestroyCallbackTestInstance:PerClassLifecyclePreDestroyCallbacksWithTwoTestMethods",
"fooPreDestroyCallbackTestInstance:PerClassLifecyclePreDestroyCallbacksWithTwoTestMethods"
);
// @formatter:on
}
Expand Down Expand Up @@ -118,6 +120,7 @@ void testOuter() {

@Nested
@ExtendWith(BarInstancePreDestroyCallback.class)
@ExtendWith(BazInstancePreDestroyCallback.class)
class InnerTestCase extends Destroyable {

@BeforeEach
Expand Down Expand Up @@ -150,7 +153,8 @@ void test() {

@TestInstance(PER_CLASS)
@ExtendWith(FooInstancePreDestroyCallback.class)
static class PerClassLifecyclePreDestroyCallbackWithTwoTestMethods extends Destroyable {
@ExtendWith(BarInstancePreDestroyCallback.class)
static class PerClassLifecyclePreDestroyCallbacksWithTwoTestMethods extends Destroyable {

@BeforeEach
void beforeEachMethod() {
Expand Down Expand Up @@ -201,4 +205,11 @@ static class BarInstancePreDestroyCallback extends AbstractTestInstancePreDestro
}
}

static class BazInstancePreDestroyCallback extends AbstractTestInstancePreDestroyCallback {

BazInstancePreDestroyCallback() {
super("baz");
}
}

}

0 comments on commit e5985c0

Please sign in to comment.