Skip to content

Commit 862e5c8

Browse files
committed
* test: update junit to 6.0.0
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent 89e128d commit 862e5c8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core-ng-test/src/main/java/core/framework/test/IntegrationExtension.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44
import org.junit.jupiter.api.extension.ExtensionContext;
55
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
66

7+
import java.util.concurrent.atomic.AtomicBoolean;
8+
79
/**
810
* @author neo
911
*/
1012
public final class IntegrationExtension implements TestInstancePostProcessor {
11-
private static final String KEY_INITIALIZED = "initialized";
13+
private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false);
1214

1315
@Override
1416
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
1517
ExtensionContext.Store store = context.getRoot().getStore(ExtensionContext.Namespace.GLOBAL);
1618
Class<?> testClass = context.getRequiredTestClass();
17-
AbstractTestModule module = store.computeIfAbsent(AbstractTestModule.class, _ -> createTestModule(testClass, store), AbstractTestModule.class);
19+
AbstractTestModule module = store.computeIfAbsent(AbstractTestModule.class, _ -> createTestModule(testClass), AbstractTestModule.class);
1820
module.inject(testInstance);
1921
}
2022

21-
private AbstractTestModule createTestModule(Class<?> testClass, ExtensionContext.Store store) {
22-
Boolean initialized = store.get(KEY_INITIALIZED, Boolean.class);
23-
if (Boolean.TRUE.equals(initialized)) throw new Error("test context failed to initialize, please check error message from previous integration test");
24-
store.computeIfAbsent(KEY_INITIALIZED, _ -> Boolean.TRUE, Boolean.class);
23+
private AbstractTestModule createTestModule(Class<?> testClass) {
24+
boolean initialized = INITIALIZED.get(); // junit 6 store doesn't support nested update, use global atomic to check loosely in test env
25+
if (initialized) throw new Error("test context failed to initialize, please check error message from previous integration test");
26+
INITIALIZED.set(true);
2527

2628
Context context = findContext(testClass);
2729
try {

0 commit comments

Comments
 (0)