Skip to content

Commit 126e8a7

Browse files
Fix setup of test execution context in ThreadLocal
- ThreadLocal must be set in setupContainer, such beforeEach method is not called by child implementation - cleanups ThreadLocal by junit - use AutoClosable
1 parent d2b5482 commit 126e8a7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/codehaus/plexus/testing/PlexusExtension.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public class PlexusExtension implements BeforeEachCallback, AfterEachCallback {
7979

8080
@Override
8181
public void beforeEach(ExtensionContext context) throws Exception {
82-
extensionContextThreadLocal.set(context);
8382
setTestBasedir(getDefaultBasedir(), context);
8483

8584
((DefaultPlexusContainer) getContainer(context))
@@ -88,6 +87,12 @@ public void beforeEach(ExtensionContext context) throws Exception {
8887
}
8988

9089
private PlexusContainer setupContainer(ExtensionContext context) {
90+
// Store the context in a thread local for static access
91+
// must be done hear as this method is always executed
92+
extensionContextThreadLocal.set(context);
93+
context.getStore(PLEXUS_EXTENSION)
94+
.put("threadLocalCloseable", (AutoCloseable) extensionContextThreadLocal::remove);
95+
9196
// ----------------------------------------------------------------------------
9297
// Context Setup
9398
// ----------------------------------------------------------------------------
@@ -175,8 +180,6 @@ public void afterEach(ExtensionContext context) throws Exception {
175180
if (container != null) {
176181
container.dispose();
177182
}
178-
context.getStore(PLEXUS_EXTENSION).remove("testBasedir", String.class);
179-
extensionContextThreadLocal.remove();
180183
}
181184

182185
/**

0 commit comments

Comments
 (0)