Interface ExtensionContext.Store
- All Superinterfaces:
Store
- All Known Implementing Classes:
NamespaceAwareStore
- Enclosing interface:
ExtensionContext
Store provides methods for extensions to save and retrieve data.
Stored values that implement ExtensionContext.Store.CloseableResource or
AutoCloseable are closed when the store is closed. For
AutoCloseable, this can be disabled by setting the
junit.jupiter.extensions.store.close.autocloseable.enabled
configuration parameter to false.
- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceDeprecated. -
Method Summary
Modifier and TypeMethodDescriptiondefault <V> VgetOrComputeIfAbsent(Class<V> type) Deprecated.Please useStore.computeIfAbsent(Class)instead.getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator) Deprecated.Please useStore.computeIfAbsent(Object, Function)instead.getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator, Class<V> requiredType) Deprecated.Please useStore.computeIfAbsent(Object, Function, Class)instead.Methods inherited from interface Store
computeIfAbsent, computeIfAbsent, computeIfAbsent, get, get, getOrDefault, put, remove, remove
-
Method Details
-
getOrComputeIfAbsent
@Deprecated(since="6.0") @API(status=DEPRECATED, since="6.0") default <V> V getOrComputeIfAbsent(Class<V> type) Deprecated.Please useStore.computeIfAbsent(Class)instead.Get the object of typetypethat is present in thisStore(keyed bytype); and otherwise invoke the default constructor fortypeto generate the object, store it, and return it.This method is a shortcut for the following, where
Xis the type of object we wish to retrieve from the store.X x = store.computeIfAbsent(X.class, key -> new X(), X.class); // Equivalent to: // X x = store.computeIfAbsent(X.class);
See
Store.computeIfAbsent(Object, Function, Class)for further details.If
typeimplementsExtensionContext.Store.CloseableResourceorAutoCloseable(unless thejunit.jupiter.extensions.store.close.autocloseable.enabledconfiguration parameter is set tofalse), then theclose()method will be invoked on the stored object when the store is closed.- Type Parameters:
V- the key and value type- Parameters:
type- the type of object to retrieve; nevernull- Returns:
- the object; never
null - Since:
- 5.1
- See Also:
-
getOrComputeIfAbsent
@Deprecated(since="6.0") @API(status=DEPRECATED, since="6.0") <K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator) Deprecated.Please useStore.computeIfAbsent(Object, Function)instead.Get the value that is stored under the suppliedkey.If no value is stored in the current
ExtensionContextfor the suppliedkey, ancestors of the context will be queried for a value with the samekeyin theNamespaceused to create this store. If no value is found for the suppliedkey, a new value will be computed by thedefaultCreator(given thekeyas input), stored, and returned.For greater type safety, consider using
Store.computeIfAbsent(Object, Function, Class)instead.If the created value is an instance of
ExtensionContext.Store.CloseableResourceorAutoCloseable(unless thejunit.jupiter.extensions.store.close.autocloseable.enabledconfiguration parameter is set tofalse), then theclose()method will be invoked on the stored object when the store is closed.- Type Parameters:
K- the key typeV- the value type- Parameters:
key- the key; nevernulldefaultCreator- the function called with the suppliedkeyto create a new value; nevernullbut may returnnull- Returns:
- the value; potentially
null - See Also:
-
getOrComputeIfAbsent
@Deprecated(since="6.0") @API(status=DEPRECATED, since="6.0") <K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator, Class<V> requiredType) Deprecated.Please useStore.computeIfAbsent(Object, Function, Class)instead.Get the value of the specified required type that is stored under the suppliedkey.If no value is stored in the current
ExtensionContextfor the suppliedkey, ancestors of the context will be queried for a value with the samekeyin theNamespaceused to create this store. If no value is found for the suppliedkey, a new value will be computed by thedefaultCreator(given thekeyas input), stored, and returned.If the created value implements
ExtensionContext.Store.CloseableResourceorAutoCloseable(unless thejunit.jupiter.extensions.store.close.autocloseable.enabledconfiguration parameter is set tofalse), then theclose()method will be invoked on the stored object when the store is closed.- Type Parameters:
K- the key typeV- the value type- Parameters:
key- the key; nevernulldefaultCreator- the function called with the suppliedkeyto create a new value; nevernullbut may returnnullrequiredType- the required type of the value; nevernull- Returns:
- the value; potentially
null - See Also:
-
AutoCloseabledirectly.