Class AbstractExtensionContext<T extends TestDescriptor>
- All Implemented Interfaces:
AutoCloseable
,ExtensionContext
- Direct Known Subclasses:
ClassExtensionContext
,DynamicExtensionContext
,JupiterEngineExtensionContext
,MethodExtensionContext
,TestTemplateExtensionContext
- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JupiterConfiguration
private final EngineExecutionListener
private final ExecutableInvoker
private final ExtensionContext
private final T
private final ExtensionValuesStore
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractExtensionContext
(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private ExtensionValuesStore
createStore
(ExtensionContext parent) Get the configuration parameter stored under the specifiedkey
.<V> Optional<V>
getConfigurationParameter
(String key, Function<String, V> transformer) Get and transform the configuration parameter stored under the specifiedkey
using the specifiedtransformer
.Get the display name for the current test or container.Get anExecutableInvoker
to invoke methods and constructors with support for dynamic resolution of parameters.Get theExecutionMode
associated with the current test or container.Get the parent extension context, if available.protected abstract Node.ExecutionMode
getRoot()
Get the rootExtensionContext
.getStore
(ExtensionContext.Namespace namespace) Get theExtensionContext.Store
for the suppliedExtensionContext.Namespace
.getTags()
Get the set of all tags for the current test or container.protected T
Get the unique ID of the current test or container.void
publishReportEntry
(Map<String, String> values) Publish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListener
in order to supply additional information to the reporting infrastructure.private ExecutionMode
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getElement, getExecutionException, getRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, getTestClass, getTestInstance, getTestInstanceLifecycle, getTestInstances, getTestMethod, publishReportEntry, publishReportEntry
-
Field Details
-
parent
-
engineExecutionListener
-
testDescriptor
-
tags
-
configuration
-
valuesStore
-
executableInvoker
-
-
Constructor Details
-
AbstractExtensionContext
AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker)
-
-
Method Details
-
createStore
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getUniqueId
Description copied from interface:ExtensionContext
Get the unique ID of the current test or container.- Specified by:
getUniqueId
in interfaceExtensionContext
- Returns:
- the unique ID of the test or container; never
null
or blank
-
getDisplayName
Description copied from interface:ExtensionContext
Get the display name for the current test or container.The display name is either a default name or a custom name configured via
@DisplayName
.For details on default display names consult the Javadoc for
TestInfo.getDisplayName()
.Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
- Specified by:
getDisplayName
in interfaceExtensionContext
- Returns:
- the display name of the test or container; never
null
or blank
-
publishReportEntry
Description copied from interface:ExtensionContext
Publish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListener
in order to supply additional information to the reporting infrastructure.- Specified by:
publishReportEntry
in interfaceExtensionContext
- Parameters:
values
- the key-value pairs to be published; nevernull
; keys and values within entries in the map also must not benull
or blank- See Also:
-
getParent
Description copied from interface:ExtensionContext
Get the parent extension context, if available.- Specified by:
getParent
in interfaceExtensionContext
- Returns:
- an
Optional
containing the parent; nevernull
but potentially empty - See Also:
-
getRoot
Description copied from interface:ExtensionContext
Get the rootExtensionContext
.- Specified by:
getRoot
in interfaceExtensionContext
- Returns:
- the root extension context; never
null
but potentially thisExtensionContext
- See Also:
-
getTestDescriptor
-
getStore
Description copied from interface:ExtensionContext
Get theExtensionContext.Store
for the suppliedExtensionContext.Namespace
.Use
getStore(Namespace.GLOBAL)
to get the default, globalExtensionContext.Namespace
.A store is bound to its extension context lifecycle. When an extension context lifecycle ends it closes its associated store. All stored values that are instances of
ExtensionContext.Store.CloseableResource
are notified by invoking theirclose()
methods.- Specified by:
getStore
in interfaceExtensionContext
- Parameters:
namespace
- theNamespace
to get the store for; nevernull
- Returns:
- the store in which to put and get objects for other invocations
working in the same namespace; never
null
- See Also:
-
getTags
Description copied from interface:ExtensionContext
Get the set of all tags for the current test or container.Tags may be declared directly on the test element or inherited from an outer context.
- Specified by:
getTags
in interfaceExtensionContext
- Returns:
- the set of tags for the test or container; never
null
but potentially empty
-
getConfigurationParameter
Description copied from interface:ExtensionContext
Get the configuration parameter stored under the specifiedkey
.If no such key is present in the
ConfigurationParameters
for the JUnit Platform, an attempt will be made to look up the value as a JVM system property. If no such system property exists, an attempt will be made to look up the value in the JUnit Platform properties file.- Specified by:
getConfigurationParameter
in interfaceExtensionContext
- Parameters:
key
- the key to look up; nevernull
or blank- Returns:
- an
Optional
containing the value; nevernull
but potentially empty - See Also:
-
getConfigurationParameter
Description copied from interface:ExtensionContext
Get and transform the configuration parameter stored under the specifiedkey
using the specifiedtransformer
.If no such key is present in the
ConfigurationParameters
for the JUnit Platform, an attempt will be made to look up the value as a JVM system property. If no such system property exists, an attempt will be made to look up the value in the JUnit Platform properties file.In case the transformer throws an exception, it will be wrapped in a
JUnitException
with a helpful message.- Specified by:
getConfigurationParameter
in interfaceExtensionContext
- Parameters:
key
- the key to look up; nevernull
or blanktransformer
- the transformer to apply in case a value is found; nevernull
- Returns:
- an
Optional
containing the value; nevernull
but potentially empty - See Also:
-
getExecutionMode
Description copied from interface:ExtensionContext
Get theExecutionMode
associated with the current test or container.- Specified by:
getExecutionMode
in interfaceExtensionContext
- Returns:
- the
ExecutionMode
of the test; nevernull
- See Also:
-
getExecutableInvoker
Description copied from interface:ExtensionContext
Get anExecutableInvoker
to invoke methods and constructors with support for dynamic resolution of parameters.- Specified by:
getExecutableInvoker
in interfaceExtensionContext
-
getPlatformExecutionMode
-
toJupiterExecutionMode
-