Class JupiterEngineExtensionContext
- java.lang.Object
-
- org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext
-
- All Implemented Interfaces:
ExtensionContext
@API(status=INTERNAL, since="5.0") public final class JupiterEngineExtensionContext extends java.lang.Object
- Since:
- 5.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
-
-
Constructor Summary
Constructors Constructor Description JupiterEngineExtensionContext(EngineExecutionListener engineExecutionListener, JupiterEngineDescriptor testDescriptor, ConfigurationParameters configurationParameters)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.util.Optional<java.lang.String>
getConfigurationParameter(java.lang.String key)
Get the configuration parameter stored under the specifiedkey
.java.lang.String
getDisplayName()
Get the display name for the current test or container.java.util.Optional<java.lang.reflect.AnnotatedElement>
getElement()
Get theAnnotatedElement
corresponding to the current extension context, if available.java.util.Optional<java.lang.Throwable>
getExecutionException()
Get the exception that was thrown during execution of the test or container associated with thisExtensionContext
, if available.java.util.Optional<ExtensionContext>
getParent()
Get the parent extension context, if available.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.java.util.Optional<java.lang.Class<?>>
getTestClass()
Get theClass
associated with the current test or container, if available.protected T
getTestDescriptor()
java.util.Optional<java.lang.Object>
getTestInstance()
Get the test instance associated with the current test or container, if available.java.util.Optional<TestInstance.Lifecycle>
getTestInstanceLifecycle()
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.java.util.Optional<java.lang.reflect.Method>
getTestMethod()
Get theMethod
associated with the current test, if available.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
.-
Methods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getRequiredTestClass, getRequiredTestInstance, getRequiredTestMethod, publishReportEntry
-
-
-
-
Constructor Detail
-
JupiterEngineExtensionContext
public JupiterEngineExtensionContext(EngineExecutionListener engineExecutionListener, JupiterEngineDescriptor testDescriptor, ConfigurationParameters configurationParameters)
-
-
Method Detail
-
getElement
public java.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
Description copied from interface:ExtensionContext
Get theAnnotatedElement
corresponding to the current extension context, if available.For example, if the current extension context encapsulates a test class, test method, test factory method, or test template method, the annotated element will be the corresponding
Class
orMethod
reference.Favor this method over more specific methods whenever the
AnnotatedElement
API suits the task at hand — for example, when looking up annotations regardless of concrete element type.- Returns:
- an
Optional
containing theAnnotatedElement
; nevernull
but potentially empty - See Also:
ExtensionContext.getTestClass()
,ExtensionContext.getTestMethod()
-
getTestClass
public java.util.Optional<java.lang.Class<?>> getTestClass()
Description copied from interface:ExtensionContext
Get theClass
associated with the current test or container, if available.- Returns:
- an
Optional
containing the class; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestClass()
-
getTestInstanceLifecycle
public java.util.Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()
Description copied from interface:ExtensionContext
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instanceLifecycle
; nevernull
but potentially empty - See Also:
TestInstance
-
getTestInstance
public java.util.Optional<java.lang.Object> getTestInstance()
Description copied from interface:ExtensionContext
Get the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instance; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestInstance()
-
getTestMethod
public java.util.Optional<java.lang.reflect.Method> getTestMethod()
Description copied from interface:ExtensionContext
Get theMethod
associated with the current test, if available.- Returns:
- an
Optional
containing the method; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestMethod()
-
getExecutionException
public java.util.Optional<java.lang.Throwable> getExecutionException()
Description copied from interface:ExtensionContext
Get the exception that was thrown during execution of the test or container associated with thisExtensionContext
, if available.This method is typically used for logging and tracing purposes. If you wish to actually handle an exception thrown during test execution, implement the
TestExecutionExceptionHandler
API.Unlike the exception passed to a
TestExecutionExceptionHandler
, an execution exception returned by this method can be any exception thrown during the invocation of a@Test
method, its surrounding@BeforeEach
and@AfterEach
methods, or a test-levelExtension
. Similarly, if thisExtensionContext
represents a test class, the execution exception returned by this method can be any exception thrown in a@BeforeAll
orAfterAll
method or a class-levelExtension
.Note, however, that this method will never return an exception swallowed by a
TestExecutionExceptionHandler
. Furthermore, if multiple exceptions have been thrown during test execution, the exception returned by this method will be the first such exception with all additional exceptions suppressed in the first one.- Returns:
- an
Optional
containing the exception thrown; nevernull
but potentially empty if test execution has not (yet) resulted in an exception
-
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
.- 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
-
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
-
-