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 JupiterConfigurationconfigurationprivate EngineExecutionListenerengineExecutionListenerprivate ExtensionContextparentprivate java.util.Set<java.lang.String>tagsprivate TtestDescriptorprivate ExtensionValuesStorevaluesStore
-
Constructor Summary
Constructors Constructor Description AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private ExtensionValuesStorecreateStore(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 specifiedkeyusing the specifiedtransformer.java.lang.StringgetDisplayName()Get the display name for the current test or container.java.util.Optional<ExtensionContext>getParent()Get the parent extension context, if available.ExtensionContextgetRoot()Get the rootExtensionContext.ExtensionContext.StoregetStore(ExtensionContext.Namespace namespace)Get theExtensionContext.Storefor the suppliedExtensionContext.Namespace.java.util.Set<java.lang.String>getTags()Get the set of all tags for the current test or container.protected TgetTestDescriptor()java.lang.StringgetUniqueId()Get the unique ID of the current test or container.voidpublishReportEntry(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.EngineExecutionListenerin order to supply additional information to the reporting infrastructure.-
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
-
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 ExtensionValuesStore valuesStore
-
-
Constructor Detail
-
AbstractExtensionContext
AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, T testDescriptor, JupiterConfiguration configuration)
-
-
Method Detail
-
createStore
private ExtensionValuesStore createStore(ExtensionContext parent)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
getUniqueId
public java.lang.String 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
public java.lang.String 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
public void publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
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:
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:ExtensionContextGet the parent extension context, if available.- Specified by:
getParentin interfaceExtensionContext- Returns:
- an
Optionalcontaining the parent; nevernullbut potentially empty - See Also:
ExtensionContext.getRoot()
-
getRoot
public ExtensionContext getRoot()
Description copied from interface:ExtensionContextGet the rootExtensionContext.- Specified by:
getRootin interfaceExtensionContext- Returns:
- the root extension context; never
nullbut potentially thisExtensionContext - See Also:
ExtensionContext.getParent()
-
getTestDescriptor
protected T getTestDescriptor()
-
getStore
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
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:
ExtensionContext.Namespace.GLOBAL
-
getTags
public java.util.Set<java.lang.String> 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
public java.util.Optional<java.lang.String> getConfigurationParameter(java.lang.String key)
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:
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: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:
System.getProperty(String),ConfigurationParameters
-
-