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 static final NamespacedHierarchicalStore.CloseAction<ExtensionContext.Namespace> private final JupiterConfigurationprivate final EngineExecutionListenerprivate final ExecutableInvokerprivate final ExtensionContextprivate final Tprivate final NamespacedHierarchicalStore<ExtensionContext.Namespace> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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 specifiedkeyusing the specifiedtransformer.Get the display name for the current test or container.Get anExecutableInvokerto invoke methods and constructors with support for dynamic resolution of parameters.Get theExecutionModeassociated with the current test or container.Get the parent extension context, if available.protected abstract Node.ExecutionModegetRoot()Get the rootExtensionContext.getStore(ExtensionContext.Namespace namespace) Get theExtensionContext.Storefor the suppliedExtensionContext.Namespace.getTags()Get the set of all tags for the current test or container.protected TGet the unique ID of the current test or container.voidpublishReportEntry(Map<String, String> values) Publish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListenerin order to supply additional information to the reporting infrastructure.private ExecutionModeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getElement, getExecutionException, getRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, getTestClass, getTestInstance, getTestInstanceLifecycle, getTestInstances, getTestMethod, publishReportEntry, publishReportEntry
-
Field Details
-
CLOSE_RESOURCES
private static final NamespacedHierarchicalStore.CloseAction<ExtensionContext.Namespace> CLOSE_RESOURCES -
parent
-
engineExecutionListener
-
testDescriptor
-
tags
-
configuration
-
valuesStore
-
executableInvoker
-
-
Constructor Details
-
AbstractExtensionContext
AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker)
-
-
Method Details
-
createStore
private NamespacedHierarchicalStore<ExtensionContext.Namespace> createStore(ExtensionContext parent) -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getUniqueId
Description copied from interface:ExtensionContextGet the unique ID of the current test or container.- Specified by:
getUniqueIdin interfaceExtensionContext- Returns:
- the unique ID of the test or container; never
nullor blank
-
getDisplayName
Description copied from interface:ExtensionContextGet 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:
getDisplayNamein interfaceExtensionContext- Returns:
- the display name of the test or container; never
nullor blank
-
publishReportEntry
Description copied from interface:ExtensionContextPublish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListenerin order to supply additional information to the reporting infrastructure.- Specified by:
publishReportEntryin interfaceExtensionContext- Parameters:
values- the key-value pairs to be published; nevernull; keys and values within entries in the map also must not benullor blank- See Also:
-
getParent
Description copied from interface:ExtensionContextGet the parent extension context, if available.- Specified by:
getParentin interfaceExtensionContext- Returns:
- an
Optionalcontaining the parent; nevernullbut potentially empty - See Also:
-
getRoot
Description copied from interface:ExtensionContextGet the rootExtensionContext.- Specified by:
getRootin interfaceExtensionContext- Returns:
- the root extension context; never
nullbut potentially thisExtensionContext - See Also:
-
getTestDescriptor
-
getStore
Description copied from interface:ExtensionContextGet theExtensionContext.Storefor 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.CloseableResourceare notified by invoking theirclose()methods.- Specified by:
getStorein interfaceExtensionContext- Parameters:
namespace- theNamespaceto 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:ExtensionContextGet 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:
getTagsin interfaceExtensionContext- Returns:
- the set of tags for the test or container; never
nullbut potentially empty
-
getConfigurationParameter
Description copied from interface:ExtensionContextGet the configuration parameter stored under the specifiedkey.If no such key is present in the
ConfigurationParametersfor 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:
getConfigurationParameterin interfaceExtensionContext- Parameters:
key- the key to look up; nevernullor blank- Returns:
- an
Optionalcontaining the value; nevernullbut potentially empty - See Also:
-
getConfigurationParameter
Description copied from interface:ExtensionContextGet and transform the configuration parameter stored under the specifiedkeyusing the specifiedtransformer.If no such key is present in the
ConfigurationParametersfor 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
JUnitExceptionwith a helpful message.- Specified by:
getConfigurationParameterin interfaceExtensionContext- Parameters:
key- the key to look up; nevernullor blanktransformer- the transformer to apply in case a value is found; nevernull- Returns:
- an
Optionalcontaining the value; nevernullbut potentially empty - See Also:
-
getExecutionMode
Description copied from interface:ExtensionContextGet theExecutionModeassociated with the current test or container.- Specified by:
getExecutionModein interfaceExtensionContext- Returns:
- the
ExecutionModeof the test; nevernull - See Also:
-
getExecutableInvoker
Description copied from interface:ExtensionContextGet anExecutableInvokerto invoke methods and constructors with support for dynamic resolution of parameters.- Specified by:
getExecutableInvokerin interfaceExtensionContext
-
getPlatformExecutionMode
-
toJupiterExecutionMode
-