Skip to content

Commit 1d2f561

Browse files
committed
Document ExtensionContext/Store hierarchy and StoreScope
Resolves #4784.
1 parent 14bd61b commit 1d2f561

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

documentation/src/docs/asciidoc/link-attributes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ endif::[]
159159
:ExtendWith: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtendWith.html[@ExtendWith]
160160
:ExtensionContext: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.html[ExtensionContext]
161161
:ExtensionContext_Store: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.Store.html[Store]
162+
:ExtensionContext_StoreScope: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.StoreScope.html[StoreScope]
162163
:InvocationInterceptor: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/InvocationInterceptor.html[InvocationInterceptor]
163164
:LifecycleMethodExecutionExceptionHandler: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/LifecycleMethodExecutionExceptionHandler.html[LifecycleMethodExecutionExceptionHandler]
164165
:ParameterResolver: {javadoc-root}/org.junit.jupiter.api/org/junit/jupiter/api/extension/ParameterResolver.html[ParameterResolver]

documentation/src/docs/asciidoc/user-guide/extensions.adoc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -854,14 +854,27 @@ to provide their functionality.
854854

855855
Usually, an extension is instantiated only once. So the question becomes relevant: How do
856856
you keep the state from one invocation of an extension to the next? The
857-
`ExtensionContext` API provides a `Store` exactly for this purpose. Extensions may put
858-
values into a store for later retrieval. See the
859-
`<<extensions-lifecycle-callbacks-timing-extension, TimingExtension>>` for an example of
860-
using the `Store` with a method-level scope. It is important to remember that values
861-
stored in an `ExtensionContext` during test execution will not be available in the
862-
surrounding `ExtensionContext`. Since `ExtensionContexts` may be nested, the scope of
863-
inner contexts may also be limited. Consult the corresponding Javadoc for details on the
864-
methods available for storing and retrieving values via the `{ExtensionContext_Store}`.
857+
`{ExtensionContext}` API provides a `{ExtensionContext_Store}` exactly for this purpose.
858+
Extensions may put values into a store for later retrieval.
859+
860+
TIP: See the `<<extensions-lifecycle-callbacks-timing-extension, TimingExtension>>` for an
861+
example of using the `Store` with a method-level scope.
862+
863+
.The `ExtensionContext` and `Store` hierarchy
864+
image::extensions_StoreHierarchy.svg[alt=UML diagram,role=text-center]
865+
866+
As illustrated by the diagram above, stores are hierarchical in nature. When looking up a
867+
value, if no value is stored in the current `ExtensionContext` for the supplied key, the
868+
stores of the context's ancestors will be queried for a value with the same key in the
869+
`Namespace` used to create this store. The root `ExtensionContext` represents the engine
870+
level so its `Store` may be used to store or cache values that are used by multiple test
871+
classes or extension. The `{ExtensionContext_StoreScope}` enum allows to go beyond even
872+
that and access the stores on the level of the current `{LauncherExecutionRequest}` or
873+
`{LauncherSession}` which can be used to share data across test engines or inject data
874+
from a registered
875+
<<launcher-api-launcher-session-listeners-custom, `LauncherSessionListener`>>,
876+
respectively. Please consult the Javadoc of `{ExtensionContext}`,
877+
`{ExtensionContext_Store}`, and `{ExtensionContext_StoreScope}` for details.
865878

866879
[[extensions-keeping-state-autocloseable-support]]
867880
[NOTE]

documentation/src/docs/asciidoc/user-guide/images/extensions_StoreHierarchy.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)