Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests lifecycle instance and methods annotated with AfterAll #26556

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.concurrent.atomic.AtomicInteger;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
Expand All @@ -27,7 +28,16 @@ public class QuarkusTestNestedPerClassLifecycleTestCase {
private final AtomicInteger counter = new AtomicInteger(0);

@BeforeAll
public void increment() {
public void incrementInBeforeAll() {
counter.incrementAndGet();
}

/**
* We're doing nothing with this code, but we want to keep it to verify the methods annotated
* with `@AfterAll` work for nested tests.
*/
@AfterAll
public void incrementInAfterAll() {
counter.incrementAndGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.AbstractMap;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -121,7 +123,7 @@ public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension
private static Class<?> actualTestClass;
private static Object actualTestInstance;
// needed for @Nested
private static List<Object> outerInstances = new ArrayList<>(1);
private static Deque<Object> outerInstances = new ArrayDeque<>(1);
private static RunningQuarkusApplication runningQuarkusApplication;
private static Pattern clonePattern;
private static Throwable firstException; //if this is set then it will be thrown from the very first test that is run, the rest are aborted
Expand Down Expand Up @@ -561,7 +563,7 @@ public void afterEach(ExtensionContext context) throws Exception {

Constructor<?> constructor = quarkusTestMethodContextClass.getConstructor(Object.class, List.class, Method.class);
return new AbstractMap.SimpleEntry<>(quarkusTestMethodContextClass,
constructor.newInstance(actualTestInstance, outerInstances, actualTestMethod));
constructor.newInstance(actualTestInstance, new ArrayList<>(outerInstances), actualTestMethod));
}

private boolean isNativeOrIntegrationTest(Class<?> clazz) {
Expand Down Expand Up @@ -1078,7 +1080,9 @@ public void afterAll(ExtensionContext context) throws Exception {
}
} finally {
currentTestClassStack.pop();
outerInstances.clear();
if (!outerInstances.isEmpty()) {
actualTestInstance = outerInstances.pop();
}
}
}

Expand All @@ -1093,7 +1097,7 @@ private void runAfterAllCallbacks(ExtensionContext context) throws Exception {
Class<?> quarkusTestContextClass = Class.forName(QuarkusTestContext.class.getName(), true,
runningQuarkusApplication.getClassLoader());
Object quarkusTestContextInstance = quarkusTestContextClass.getConstructor(Object.class, List.class)
.newInstance(actualTestInstance, outerInstances);
.newInstance(actualTestInstance, new ArrayList<>(outerInstances));

ClassLoader original = setCCL(runningQuarkusApplication.getClassLoader());
try {
Expand Down