Class AbstractExtensionContext<T extends TestDescriptor>
- java.lang.Object
-
- org.junit.jupiter.engine.descriptor.AbstractExtensionContext<T>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,ExtensionContext
- Direct Known Subclasses:
ClassExtensionContext
,DynamicExtensionContext
,JupiterEngineExtensionContext
,MethodExtensionContext
,TestTemplateExtensionContext
abstract class AbstractExtensionContext<T extends TestDescriptor> extends java.lang.Object implements ExtensionContext, java.lang.AutoCloseable
- Since:
- 5.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
-
-
Field Summary
Fields Modifier and Type Field Description private static NamespacedHierarchicalStore.CloseAction<ExtensionContext.Namespace>
CLOSE_RESOURCES
private JupiterConfiguration
configuration
private EngineExecutionListener
engineExecutionListener
private ExecutableInvoker
executableInvoker
private ExtensionContext
parent
private java.util.Set<java.lang.String>
tags
private T
testDescriptor
private NamespacedHierarchicalStore<ExtensionContext.Namespace>
valuesStore
-
Constructor Summary
Constructors Constructor Description AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
private NamespacedHierarchicalStore<ExtensionContext.Namespace>
createStore(ExtensionContext parent)
java.util.Optional<java.lang.String>
getConfigurationParameter(java.lang.String key)
Get the configuration parameter stored under the specifiedkey
.<V> java.util.Optional<V>
getConfigurationParameter(java.lang.String key, java.util.function.Function<java.lang.String,V> transformer)
Get and transform the configuration parameter stored under the specifiedkey
using the specifiedtransformer
.java.lang.String
getDisplayName()
Get the display name for the current test or container.ExecutableInvoker
getExecutableInvoker()
Get anExecutableInvoker
to invoke methods and constructors with support for dynamic resolution of parameters.ExecutionMode
getExecutionMode()
Get theExecutionMode
associated with the current test or container.java.util.Optional<ExtensionContext>
getParent()
Get the parent extension context, if available.protected abstract Node.ExecutionMode
getPlatformExecutionMode()
ExtensionContext
getRoot()
Get the rootExtensionContext
.ExtensionContext.Store
getStore(ExtensionContext.Namespace namespace)
Get theExtensionContext.Store
for the suppliedExtensionContext.Namespace
.java.util.Set<java.lang.String>
getTags()
Get the set of all tags for the current test or container.protected T
getTestDescriptor()
java.lang.String
getUniqueId()
Get the unique ID of the current test or container.void
publishReportEntry(java.util.Map<java.lang.String,java.lang.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
toJupiterExecutionMode(Node.ExecutionMode mode)
-
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 Detail
-
CLOSE_RESOURCES
private static final NamespacedHierarchicalStore.CloseAction<ExtensionContext.Namespace> CLOSE_RESOURCES
-
parent
private final ExtensionContext parent
-
engineExecutionListener
private final EngineExecutionListener engineExecutionListener
-
testDescriptor
private final T extends TestDescriptor testDescriptor
-
tags
private final java.util.Set<java.lang.String> tags
-
configuration
private final JupiterConfiguration configuration
-
valuesStore
private final NamespacedHierarchicalStore<ExtensionContext.Namespace> valuesStore
-
executableInvoker
private final ExecutableInvoker executableInvoker
-
-
Constructor Detail
-
AbstractExtensionContext
AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration, ExecutableInvoker executableInvoker)
-
-
Method Detail
-
createStore
private NamespacedHierarchicalStore<ExtensionContext.Namespace> createStore(ExtensionContext parent)
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
getUniqueId
public java.lang.String 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
public java.lang.String 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
public void publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
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:
ExtensionContext.publishReportEntry(String, String)
,ExtensionContext.publishReportEntry(String)
,EngineExecutionListener.reportingEntryPublished(org.junit.platform.engine.TestDescriptor, org.junit.platform.engine.reporting.ReportEntry)
-
getParent
public java.util.Optional<ExtensionContext> 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:
ExtensionContext.getRoot()
-
getRoot
public ExtensionContext 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:
ExtensionContext.getParent()
-
getTestDescriptor
protected T getTestDescriptor()
-
getStore
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
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:
ExtensionContext.Namespace.GLOBAL
-
getTags
public java.util.Set<java.lang.String> 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
public java.util.Optional<java.lang.String> getConfigurationParameter(java.lang.String key)
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:
System.getProperty(String)
,ConfigurationParameters
-
getConfigurationParameter
public <V> java.util.Optional<V> getConfigurationParameter(java.lang.String key, java.util.function.Function<java.lang.String,V> transformer)
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:
System.getProperty(String)
,ConfigurationParameters
-
getExecutionMode
public ExecutionMode 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:
ExecutionMode
-
getExecutableInvoker
public ExecutableInvoker 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
protected abstract Node.ExecutionMode getPlatformExecutionMode()
-
toJupiterExecutionMode
private ExecutionMode toJupiterExecutionMode(Node.ExecutionMode mode)
-
-