Class NamespaceAwareStore
- All Implemented Interfaces:
ExtensionContext.Store
- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext.Store
ExtensionContext.Store.CloseableResource
-
Constructor Summary
ConstructorDescriptionNamespaceAwareStore(ExtensionValuesStore valuesStore, ExtensionContext.Namespace namespace)
-
Method Summary
Modifier and TypeMethodDescriptionGet the value that is stored under the suppliedkey
.<T> T
Get the value of the specified required type that is stored under the suppliedkey
.<K, V> Object
getOrComputeIfAbsent(K key, Function<K,V> defaultCreator)
Get the value that is stored under the suppliedkey
.<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 suppliedkey
.void
Store avalue
for later retrieval under the suppliedkey
.Remove the value that was previously stored under the suppliedkey
.<T> T
Remove the value of the specified required type that was previously stored under the suppliedkey
.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.Store
getOrComputeIfAbsent, getOrDefault
-
Constructor Details
-
NamespaceAwareStore
-
-
Method Details
-
get
Description copied from interface:ExtensionContext.Store
Get the value that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store.For greater type safety, consider using
ExtensionContext.Store.get(Object, Class)
instead.- Specified by:
get
in interfaceExtensionContext.Store
- Parameters:
key
- the key; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.get(Object, Class)
,ExtensionContext.Store.getOrDefault(Object, Class, Object)
-
get
Description copied from interface:ExtensionContext.Store
Get the value of the specified required type that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store.- Specified by:
get
in interfaceExtensionContext.Store
- Type Parameters:
T
- the value type- Parameters:
key
- the key; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.get(Object)
,ExtensionContext.Store.getOrDefault(Object, Class, Object)
-
getOrComputeIfAbsent
Description copied from interface:ExtensionContext.Store
Get the value that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store. If no value is found for the suppliedkey
, a new value will be computed by thedefaultCreator
(given thekey
as input), stored, and returned.For greater type safety, consider using
ExtensionContext.Store.getOrComputeIfAbsent(Object, Function, Class)
instead.If the created value is an instance of
ExtensionContext.Store.CloseableResource
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
getOrComputeIfAbsent
in interfaceExtensionContext.Store
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- the key; nevernull
defaultCreator
- the function called with the suppliedkey
to create a new value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,ExtensionContext.Store.getOrComputeIfAbsent(Object, Function, Class)
,ExtensionContext.Store.CloseableResource
-
getOrComputeIfAbsent
Description copied from interface:ExtensionContext.Store
Get the value of the specified required type that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store. If no value is found for the suppliedkey
, a new value will be computed by thedefaultCreator
(given thekey
as input), stored, and returned.If
requiredType
implementsExtensionContext.Store.CloseableResource
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
getOrComputeIfAbsent
in interfaceExtensionContext.Store
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- the key; nevernull
defaultCreator
- the function called with the suppliedkey
to create a new value; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,ExtensionContext.Store.getOrComputeIfAbsent(Object, Function)
,ExtensionContext.Store.CloseableResource
-
put
Description copied from interface:ExtensionContext.Store
Store avalue
for later retrieval under the suppliedkey
.A stored
value
is visible in childExtensionContexts
for the store'sNamespace
unless they overwrite it.If the
value
is an instance ofExtensionContext.Store.CloseableResource
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
put
in interfaceExtensionContext.Store
- Parameters:
key
- the key under which the value should be stored; nevernull
value
- the value to store; may benull
- See Also:
ExtensionContext.Store.CloseableResource
-
remove
Description copied from interface:ExtensionContext.Store
Remove the value that was previously stored under the suppliedkey
.The value will only be removed in the current
ExtensionContext
, not in ancestors. In addition, theExtensionContext.Store.CloseableResource
API will not be honored for values that are manually removed via this method.For greater type safety, consider using
ExtensionContext.Store.remove(Object, Class)
instead.- Specified by:
remove
in interfaceExtensionContext.Store
- Parameters:
key
- the key; nevernull
- Returns:
- the previous value or
null
if no value was present for the specified key - See Also:
ExtensionContext.Store.remove(Object, Class)
-
remove
Description copied from interface:ExtensionContext.Store
Remove the value of the specified required type that was previously stored under the suppliedkey
.The value will only be removed in the current
ExtensionContext
, not in ancestors. In addition, theExtensionContext.Store.CloseableResource
API will not be honored for values that are manually removed via this method.- Specified by:
remove
in interfaceExtensionContext.Store
- Type Parameters:
T
- the value type- Parameters:
key
- the key; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the previous value or
null
if no value was present for the specified key - See Also:
ExtensionContext.Store.remove(Object)
-