Skip to content

TestWatcher can no longer access data in ExtensionContext.Store #3944

@joerg1985

Description

@joerg1985

After upgrading from 5.10.2 to 5.11.0 a org.junit.jupiter.api.extension.TestWatcher can no longer access store data. Instead, it now fails with org.junit.jupiter.api.extension.ExtensionContextException: A NamespacedHierarchicalStore cannot be modified or queried after it has been closed.

In my mind the intention of the store is to allow extensions to attach data to the context, so this data should be accessible at least until all extensions related to the context are processed.

Steps to reproduce

import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;

class Mock extends TestCase.Handling<TestCase<?, ?>> implements BeforeTestExecutionCallback, TestWatcher {

    static final ExtensionContext.Namespace PACKAGE_PRIVATE = ExtensionContext.Namespace.create(new Object());

    @Override
    public void beforeTestExecution(ExtensionContext context) throws Exception {
        ExtensionContext.Store store = context.getStore(PACKAGE_PRIVATE);

        store.put("value", new Object());
    }

    @Override
    public void testSuccessful(ExtensionContext context) {
        ExtensionContext.Store store = context.getStore(PACKAGE_PRIVATE);

        store.get("value");
    }

}

Context

  • Used versions (Jupiter/Vintage/Platform): 5.11.0
  • Build Tool/IDE: maven 3

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions