Top Description Inners Methods
org.junit.jupiter.api.extension

public Interface ExtensionContext

Annotations
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.EXPERIMENTAL, .API.Status.STABLE

ExtensionContext encapsulates the context in which the current test or container is being executed.

Extensions are provided an instance of ExtensionContext to perform their work.

Since
5.0
See Also
Store, Namespace

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ExtensionContext.Namespace

A Namespace is used to provide a scope for data saved by extensions within a Store.

public static interface
ExtensionContext.Store

Store provides methods for extensions to save and retrieve data.

Method Summary

Modifier and TypeMethod and Description
public Optional<String>

Returns:

an Optional containing the value; never null but potentially empty
getConfigurationParameter
(String
the key to look up; never null or blank
key
)

Get the configuration parameter stored under the specified key.

public <T> Optional<T>

Returns:

an Optional containing the value; never null but potentially empty
getConfigurationParameter
(String
the key to look up; never null or blank
key
,
Function<String, T>
the transformer to apply in case a value is found; never null
transformer
)

Get and transform the configuration parameter stored under the specified key using the specified transformer.

public String

Returns:

the display name of the test or container; never null or blank
getDisplayName
()

Get the display name for the current test or container.

public Optional<AnnotatedElement>

Returns:

an Optional containing the AnnotatedElement; never null but potentially empty
getElement
()

Get the AnnotatedElement corresponding to the current extension context, if available.

public ExecutableInvoker
getExecutableInvoker()

Get an ExecutableInvoker to invoke methods and constructors with support for dynamic resolution of parameters.

public Optional<Throwable>

Returns:

an Optional containing the exception thrown; never null but potentially empty if test execution has not (yet) resulted in an exception
getExecutionException
()

Get the exception that was thrown during execution of the test or container associated with this ExtensionContext, if available.

public ExecutionMode

Returns:

the ExecutionMode of the test; never null
getExecutionMode
()

Get the ExecutionMode associated with the current test or container.

public Optional<ExtensionContext>

Returns:

an Optional containing the parent; never null but potentially empty
getParent
()

Get the parent extension context, if available.

public default Class<?>

Returns:

the test class; never null
getRequiredTestClass
()

Get the required Class associated with the current test or container.

public default Object

Returns:

the test instance; never null
getRequiredTestInstance
()

Get the required test instance associated with the current test or container.

public default TestInstances

Returns:

the test instances; never null
getRequiredTestInstances
()

Get the required test instances associated with the current test or container.

public default Method

Returns:

the test method; never null
getRequiredTestMethod
()

Get the required Method associated with the current test or container.

public ExtensionContext

Returns:

the root extension context; never null but potentially this ExtensionContext
getRoot
()

Get the root ExtensionContext.

public ExtensionContext.Store

Returns:

the store in which to put and get objects for other invocations working in the same namespace; never null
getStore
(ExtensionContext.Namespace
the Namespace to get the store for; never null
namespace
)

Get the Store for the supplied Namespace.

public Set<String>

Returns:

the set of tags for the test or container; never null but potentially empty
getTags
()

Get the set of all tags for the current test or container.

public Optional<Class<?>>

Returns:

an Optional containing the class; never null but potentially empty
getTestClass
()

Get the Class associated with the current test or container, if available.

public Optional<Object>

Returns:

an Optional containing the test instance; never null but potentially empty
getTestInstance
()

Get the test instance associated with the current test or container, if available.

public Optional<TestInstance.Lifecycle>

Returns:

an Optional containing the test instance Lifecycle; never null but potentially empty
getTestInstanceLifecycle
()

Get the Lifecycle of the test instance associated with the current test or container, if available.

public Optional<TestInstances>

Returns:

an Optional containing the test instances; never null but potentially empty
getTestInstances
()

Get the test instances associated with the current test or container, if available.

public Optional<Method>

Returns:

an Optional containing the method; never null but potentially empty
getTestMethod
()

Get the Method associated with the current test, if available.

public String

Returns:

the unique ID of the test or container; never null or blank
getUniqueId
()

Get the unique ID of the current test or container.

public void
publishReportEntry(Map<String, String>
the key-value pairs to be published; never null; keys and values within entries in the map also must not be null or blank
map
)

Publish a map of key-value pairs to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

public default void
publishReportEntry(String
the key of the published pair; never null or blank
key
,
String
the value of the published pair; never null or blank
value
)

Publish the specified key-value pair to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

public default void
publishReportEntry(String
the value to be published; never null or blank
value
)

Publish the specified value to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

Method Detail

getConfigurationParameterback to summary
public Optional<String> getConfigurationParameter(String key)

Get the configuration parameter stored under the specified key.

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.

Parameters
key:String

the key to look up; never null or blank

Returns:Optional<String>

an Optional containing the value; never null but potentially empty

Annotations
@API
status:STABLE
since:5.1
Since
5.1
See Also
System#getProperty(String), org.junit.platform.engine.ConfigurationParameters
getConfigurationParameterback to summary
public <T> Optional<T> getConfigurationParameter(String key, Function<String, T> transformer)

Get and transform the configuration parameter stored under the specified key using the specified transformer.

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 org.junit.platform.commons.JUnitException with a helpful message.

Parameters
key:String

the key to look up; never null or blank

transformer:Function<String, T>

the transformer to apply in case a value is found; never null

Returns:Optional<T>

an Optional containing the value; never null but potentially empty

Annotations
@API
status:STABLE
since:5.10
Since
5.7
See Also
System#getProperty(String), org.junit.platform.engine.ConfigurationParameters
getDisplayNameback to summary
public String getDisplayName()

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 org.junit.jupiter.api.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.

Returns:String

the display name of the test or container; never null or blank

getElementback to summary
public Optional<AnnotatedElement> getElement()

Get the AnnotatedElement 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 or Method 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:Optional<AnnotatedElement>

an Optional containing the AnnotatedElement; never null but potentially empty

See Also
getTestClass(), getTestMethod()
getExecutableInvokerback to summary
public ExecutableInvoker getExecutableInvoker()

Get an ExecutableInvoker to invoke methods and constructors with support for dynamic resolution of parameters.

Annotations
@API
status:EXPERIMENTAL
since:5.9
Since
5.9
getExecutionExceptionback to summary
public Optional<Throwable> getExecutionException()

Get the exception that was thrown during execution of the test or container associated with this ExtensionContext, 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-level Extension. Similarly, if this ExtensionContext represents a test class, the execution exception returned by this method can be any exception thrown in a @BeforeAll or AfterAll method or a class-level Extension.

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:Optional<Throwable>

an Optional containing the exception thrown; never null but potentially empty if test execution has not (yet) resulted in an exception

getExecutionModeback to summary
public ExecutionMode getExecutionMode()

Get the ExecutionMode associated with the current test or container.

Returns:ExecutionMode

the ExecutionMode of the test; never null

Annotations
@API
status:STABLE
since:5.8.1
Since
5.8.1
See Also
@ExecutionMode
getParentback to summary
public Optional<ExtensionContext> getParent()

Get the parent extension context, if available.

Returns:Optional<ExtensionContext>

an Optional containing the parent; never null but potentially empty

See Also
getRoot()
getRequiredTestClassback to summary
public default Class<?> getRequiredTestClass()

Get the required Class associated with the current test or container.

Use this method as an alternative to getTestClass() for use cases in which the test class is required to be present.

Returns:Class<?>

the test class; never null

Exceptions
PreconditionViolationException:
if the test class is not present in this ExtensionContext
getRequiredTestInstanceback to summary
public default Object getRequiredTestInstance()

Get the required test instance associated with the current test or container.

Use this method as an alternative to getTestInstance() for use cases in which the test instance is required to be present.

Returns:Object

the test instance; never null

Exceptions
PreconditionViolationException:
if the test instance is not present in this ExtensionContext
See Also
getRequiredTestInstances()
getRequiredTestInstancesback to summary
public default TestInstances getRequiredTestInstances()

Get the required test instances associated with the current test or container.

Use this method as an alternative to getTestInstances() for use cases in which the test instances are required to be present.

Returns:TestInstances

the test instances; never null

Annotations
@API
status:STABLE
since:5.7
Exceptions
PreconditionViolationException:
if the test instances are not present in this ExtensionContext
Since
5.4
getRequiredTestMethodback to summary
public default Method getRequiredTestMethod()

Get the required Method associated with the current test or container.

Use this method as an alternative to getTestMethod() for use cases in which the test method is required to be present.

Returns:Method

the test method; never null

Exceptions
PreconditionViolationException:
if the test method is not present in this ExtensionContext
getRootback to summary
public ExtensionContext getRoot()

Get the root ExtensionContext.

Returns:ExtensionContext

the root extension context; never null but potentially this ExtensionContext

See Also
getParent()
getStoreback to summary
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)

Get the Store for the supplied Namespace.

Use getStore(Namespace.GLOBAL) to get the default, global 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 their close() methods.

Parameters
namespace:ExtensionContext.Namespace

the Namespace to get the store for; never null

Returns:ExtensionContext.Store

the store in which to put and get objects for other invocations working in the same namespace; never null

See Also
Namespace#GLOBAL
getTagsback to summary
public Set<String> getTags()

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.

Returns:Set<String>

the set of tags for the test or container; never null but potentially empty

getTestClassback to summary
public Optional<Class<?>> getTestClass()

Get the Class associated with the current test or container, if available.

Returns:Optional<Class<?>>

an Optional containing the class; never null but potentially empty

See Also
getRequiredTestClass()
getTestInstanceback to summary
public Optional<Object> getTestInstance()

Get the test instance associated with the current test or container, if available.

Returns:Optional<Object>

an Optional containing the test instance; never null but potentially empty

See Also
getRequiredTestInstance(), getTestInstances()
getTestInstanceLifecycleback to summary
public Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()

Get the Lifecycle of the test instance associated with the current test or container, if available.

Returns:Optional<TestInstance.Lifecycle>

an Optional containing the test instance Lifecycle; never null but potentially empty

Annotations
@API
status:STABLE
since:5.1
Since
5.1
See Also
@TestInstance
getTestInstancesback to summary
public Optional<TestInstances> getTestInstances()

Get the test instances associated with the current test or container, if available.

While top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.

Returns:Optional<TestInstances>

an Optional containing the test instances; never null but potentially empty

Annotations
@API
status:STABLE
since:5.7
Since
5.4
See Also
getRequiredTestInstances()
getTestMethodback to summary
public Optional<Method> getTestMethod()

Get the Method associated with the current test, if available.

Returns:Optional<Method>

an Optional containing the method; never null but potentially empty

See Also
getRequiredTestMethod()
getUniqueIdback to summary
public String getUniqueId()

Get the unique ID of the current test or container.

Returns:String

the unique ID of the test or container; never null or blank

publishReportEntryback to summary
public void publishReportEntry(Map<String, String> map)

Publish a map of key-value pairs to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

Parameters
map:Map<String, String>

the key-value pairs to be published; never null; keys and values within entries in the map also must not be null or blank

See Also
publishReportEntry(String, String), publishReportEntry(String), org.junit.platform.engine.EngineExecutionListener#reportingEntryPublished
publishReportEntryback to summary
public default void publishReportEntry(String key, String value)

Publish the specified key-value pair to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

Parameters
key:String

the key of the published pair; never null or blank

value:String

the value of the published pair; never null or blank

See Also
publishReportEntry(Map), publishReportEntry(String), org.junit.platform.engine.EngineExecutionListener#reportingEntryPublished
publishReportEntryback to summary
public default void publishReportEntry(String value)

Publish the specified value to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

This method delegates to publishReportEntry(String, String), supplying "value" as the key and the supplied value argument as the value.

Parameters
value:String

the value to be published; never null or blank

Annotations
@API
status:STABLE
since:5.3
Since
5.3
See Also
publishReportEntry(Map), publishReportEntry(String, String), org.junit.platform.engine.EngineExecutionListener#reportingEntryPublished
org.junit.jupiter.api.extension back to summary

public Class ExtensionContext.Namespace

extends Object
Class Inheritance

A Namespace is used to provide a scope for data saved by extensions within a Store.

Storing data in custom namespaces allows extensions to avoid accidentally mixing data between extensions or across different invocations within the lifecycle of a single extension.

Field Summary

Modifier and TypeField and Description
public static final ExtensionContext.Namespace
GLOBAL

The default, global namespace which allows access to stored data from all extensions.

private final List<Object>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ExtensionContext.Namespace

Returns:

new namespace; never null
append
(Object... parts)

Create a new namespace by appending the supplied parts to the existing sequence of parts in this namespace.

public static ExtensionContext.Namespace
create(Object... parts)

Create a namespace which restricts access to data to all extensions which use the same sequence of parts for creating a namespace.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

GLOBALback to summary
public static final ExtensionContext.Namespace GLOBAL

The default, global namespace which allows access to stored data from all extensions.

partsback to summary
private final List<Object> parts

Constructor Detail

Namespaceback to summary
private Namespace(List<Object> parts)

Method Detail

appendback to summary
public ExtensionContext.Namespace append(Object... parts)

Create a new namespace by appending the supplied parts to the existing sequence of parts in this namespace.

Returns:ExtensionContext.Namespace

new namespace; never null

Annotations
@API
status:STABLE
since:5.10
Since
5.8
createback to summary
public static ExtensionContext.Namespace create(Object... parts)

Create a namespace which restricts access to data to all extensions which use the same sequence of parts for creating a namespace.

The order of the parts is significant.

Internally the parts are compared using Object#equals(Object).

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
org.junit.jupiter.api.extension back to summary

public Interface ExtensionContext.Store


Store provides methods for extensions to save and retrieve data.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ExtensionContext.Store.CloseableResource

Classes implementing this interface indicate that they want to close some underlying resource or resources when the enclosing Store is closed.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the value; potentially null
get
(Object
the key; never null
key
)

Get the value that is stored under the supplied key.

public <
the value type
V
>
V

Returns:

the value; potentially null
get
(Object
the key; never null
key
,
Class<V>
the required type of the value; never null
requiredType
)

Get the value of the specified required type that is stored under the supplied key.

public default <
the key and value type
V
>
V

Returns:

the object; never null
getOrComputeIfAbsent
(Class<V>
the type of object to retrieve; never null
type
)

Get the object of type type that is present in this Store (keyed by type); and otherwise invoke the default constructor for type to generate the object, store it, and return it.

public <
the key type
K
,
the value type
V
>
Object

Returns:

the value; potentially null
getOrComputeIfAbsent
(K
the key; never null
key
,
Function<K, V>
the function called with the supplied key to create a new value; never null but may return null
defaultCreator
)

Get the value that is stored under the supplied key.

public <
the key type
K
,
the value type
V
>
V

Returns:

the value; potentially null
getOrComputeIfAbsent
(K
the key; never null
key
,
Function<K, V>
the function called with the supplied key to create a new value; never null but may return null
defaultCreator
,
Class<V>
the required type of the value; never null
requiredType
)

Get the value of the specified required type that is stored under the supplied key.

public default <
the value type
V
>
V

Returns:

the value; potentially null
getOrDefault
(Object
the key; never null
key
,
Class<V>
the required type of the value; never null
requiredType
,
V
the default value
defaultValue
)

Get the value of the specified required type that is stored under the supplied key, or the supplied defaultValue if no value is found for the supplied key in this store or in an ancestor.

public void
put(Object
the key under which the value should be stored; never null
key
,
Object
the value to store; may be null
value
)

Store a value for later retrieval under the supplied key.

public Object

Returns:

the previous value or null if no value was present for the specified key
remove
(Object
the key; never null
key
)

Remove the value that was previously stored under the supplied key.

public <
the value type
V
>
V

Returns:

the previous value or null if no value was present for the specified key
remove
(Object
the key; never null
key
,
Class<V>
the required type of the value; never null
requiredType
)

Remove the value of the specified required type that was previously stored under the supplied key.

Method Detail

getback to summary
public Object get(Object key)

Get the value that is stored under the supplied key.

If no value is stored in the current ExtensionContext for the supplied key, ancestors of the context will be queried for a value with the same key in the Namespace used to create this store.

For greater type safety, consider using get(Object, Class) instead.

Parameters
key:Object

the key; never null

Returns:Object

the value; potentially null

See Also
get(Object, Class), getOrDefault(Object, Class, Object)
getback to summary
public <V> V get(Object key, Class<V> requiredType)

Get the value of the specified required type that is stored under the supplied key.

If no value is stored in the current ExtensionContext for the supplied key, ancestors of the context will be queried for a value with the same key in the Namespace used to create this store.

Parameters
<V>
the value type
key:Object

the key; never null

requiredType:Class<V>

the required type of the value; never null

Returns:V

the value; potentially null

See Also
get(Object), getOrDefault(Object, Class, Object)
getOrComputeIfAbsentback to summary
public default <V> V getOrComputeIfAbsent(Class<V> type)

Get the object of type type that is present in this Store (keyed by type); and otherwise invoke the default constructor for type to generate the object, store it, and return it.

This method is a shortcut for the following, where X is the type of object we wish to retrieve from the store.

X x = store.getOrComputeIfAbsent(X.class, key -> new X(), X.class);
// Equivalent to:
// X x = store.getOrComputeIfAbsent(X.class);

See getOrComputeIfAbsent(Object, Function, Class) for further details.

If type implements ExtensionContext.Store.CloseableResource the close() method will be invoked on the stored object when the store is closed.

Parameters
<V>
the key and value type
type:Class<V>

the type of object to retrieve; never null

Returns:V

the object; never null

Annotations
@API
status:STABLE
since:5.1
Since
5.1
See Also
getOrComputeIfAbsent(Object, Function), getOrComputeIfAbsent(Object, Function, Class), CloseableResource
getOrComputeIfAbsentback to summary
public <K, V> Object getOrComputeIfAbsent(K key, Function<K, V> defaultCreator)

Get the value that is stored under the supplied key.

If no value is stored in the current ExtensionContext for the supplied key, ancestors of the context will be queried for a value with the same key in the Namespace used to create this store. If no value is found for the supplied key, a new value will be computed by the defaultCreator (given the key as input), stored, and returned.

For greater type safety, consider using getOrComputeIfAbsent(Object, Function, Class) instead.

If the created value is an instance of ExtensionContext.Store.CloseableResource the close() method will be invoked on the stored object when the store is closed.

Parameters
<K>
the key type
<V>
the value type
key:K

the key; never null

defaultCreator:Function<K, V>

the function called with the supplied key to create a new value; never null but may return null

Returns:Object

the value; potentially null

See Also
getOrComputeIfAbsent(Class), getOrComputeIfAbsent(Object, Function, Class), CloseableResource
getOrComputeIfAbsentback to summary
public <K, V> V getOrComputeIfAbsent(K key, Function<K, V> defaultCreator, Class<V> requiredType)

Get the value of the specified required type that is stored under the supplied key.

If no value is stored in the current ExtensionContext for the supplied key, ancestors of the context will be queried for a value with the same key in the Namespace used to create this store. If no value is found for the supplied key, a new value will be computed by the defaultCreator (given the key as input), stored, and returned.

If requiredType implements ExtensionContext.Store.CloseableResource the close() method will be invoked on the stored object when the store is closed.

Parameters
<K>
the key type
<V>
the value type
key:K

the key; never null

defaultCreator:Function<K, V>

the function called with the supplied key to create a new value; never null but may return null

requiredType:Class<V>

the required type of the value; never null

Returns:V

the value; potentially null

See Also
getOrComputeIfAbsent(Class), getOrComputeIfAbsent(Object, Function), CloseableResource
getOrDefaultback to summary
public default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue)

Get the value of the specified required type that is stored under the supplied key, or the supplied defaultValue if no value is found for the supplied key in this store or in an ancestor.

If no value is stored in the current ExtensionContext for the supplied key, ancestors of the context will be queried for a value with the same key in the Namespace used to create this store.

Parameters
<V>
the value type
key:Object

the key; never null

requiredType:Class<V>

the required type of the value; never null

defaultValue:V

the default value

Returns:V

the value; potentially null

Annotations
@API
status:STABLE
since:5.5
Since
5.5
See Also
get(Object, Class)
putback to summary
public void put(Object key, Object value)

Store a value for later retrieval under the supplied key.

A stored value is visible in child ExtensionContexts for the store's Namespace unless they overwrite it.

If the value is an instance of ExtensionContext.Store.CloseableResource the close() method will be invoked on the stored object when the store is closed.

Parameters
key:Object

the key under which the value should be stored; never null

value:Object

the value to store; may be null

See Also
CloseableResource
removeback to summary
public Object remove(Object key)

Remove the value that was previously stored under the supplied key.

The value will only be removed in the current ExtensionContext, not in ancestors. In addition, the CloseableResource API will not be honored for values that are manually removed via this method.

For greater type safety, consider using remove(Object, Class) instead.

Parameters
key:Object

the key; never null

Returns:Object

the previous value or null if no value was present for the specified key

See Also
remove(Object, Class)
removeback to summary
public <V> V remove(Object key, Class<V> requiredType)

Remove the value of the specified required type that was previously stored under the supplied key.

The value will only be removed in the current ExtensionContext, not in ancestors. In addition, the CloseableResource API will not be honored for values that are manually removed via this method.

Parameters
<V>
the value type
key:Object

the key; never null

requiredType:Class<V>

the required type of the value; never null

Returns:V

the previous value or null if no value was present for the specified key

See Also
remove(Object)
org.junit.jupiter.api.extension back to summary

public Interface ExtensionContext.Store.CloseableResource

Annotations
@API
status:STABLE
since:5.1

Classes implementing this interface indicate that they want to close some underlying resource or resources when the enclosing Store is closed.

Note that the CloseableResource API is only honored for objects stored within an extension context Store.

The resources stored in a Store are closed in the inverse order they were added in.

Since
5.1

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close underlying resources.

Method Detail

closeback to summary
public void close() throws Throwable

Close underlying resources.

Exceptions
Throwable:
any throwable will be caught and rethrown