Class NamespaceAwareStore

java.lang.Object
org.junit.jupiter.engine.execution.NamespaceAwareStore
All Implemented Interfaces:
ExtensionContext.Store, Store

@API(status=INTERNAL, since="5.0") public class NamespaceAwareStore extends Object implements ExtensionContext.Store
Since:
5.0
  • Constructor Details

  • Method Details

    • createAdapter

      public static NamespaceAwareStore createAdapter(NamespacedHierarchicalStore<Namespace> valuesStore, Namespace namespace)
    • get

      public @Nullable Object get(Object key)
      Description copied from interface: Store
      Get the value that is stored under the supplied key.

      If no value is stored in this store for the supplied key, parent stores (if any) will be queried for a value with the same key in the Namespace used to create this store.

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

      Specified by:
      get in interface Store
      Parameters:
      key - the key; never null
      Returns:
      the value; potentially null
      See Also:
    • get

      public <T> @Nullable T get(Object key, Class<T> requiredType)
      Description copied from interface: Store
      Get the value of the specified required type that is stored under the supplied key.

      If no value is stored in this store for the supplied key, parent stores (if any) will be queried for a value with the same key in the Namespace used to create this store.

      Specified by:
      get in interface Store
      Type Parameters:
      T - the value type
      Parameters:
      key - the key; never null
      requiredType - the required type of the value; never null
      Returns:
      the value; potentially null
      See Also:
    • getOrComputeIfAbsent

      public <K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator)
      Description copied from interface: ExtensionContext.Store
      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 Store.computeIfAbsent(Object, Function, Class) instead.

      If the created value is an instance of ExtensionContext.Store.CloseableResource or AutoCloseable (unless the junit.jupiter.extensions.store.close.autocloseable.enabled configuration parameter is set to false), then the close() method will be invoked on the stored object when the store is closed.

      Specified by:
      getOrComputeIfAbsent in interface ExtensionContext.Store
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key; never null
      defaultCreator - the function called with the supplied key to create a new value; never null but may return null
      Returns:
      the value; potentially null
      See Also:
    • getOrComputeIfAbsent

      public <K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator, Class<V> requiredType)
      Description copied from interface: ExtensionContext.Store
      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 the created value implements ExtensionContext.Store.CloseableResource or AutoCloseable (unless the junit.jupiter.extensions.store.close.autocloseable.enabled configuration parameter is set to false), then the close() method will be invoked on the stored object when the store is closed.

      Specified by:
      getOrComputeIfAbsent in interface ExtensionContext.Store
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key; never null
      defaultCreator - the function called with the supplied key to create a new value; never null but may return null
      requiredType - the required type of the value; never null
      Returns:
      the value; potentially null
      See Also:
    • computeIfAbsent

      public <K,V> Object computeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator)
      Description copied from interface: Store
      Return the value of the specified required type that is stored under the supplied key.

      If no value is stored in this store for the supplied key, parent stores (if any) 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 or the value is null, a new value will be computed by the defaultCreator (given the key as input), stored, and returned.

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

      If the created value is an instance of AutoCloseable, then the close() method will be invoked on the stored object when the store is closed, unless documented otherwise by a subinterface.

      Specified by:
      computeIfAbsent in interface Store
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key; never null
      defaultCreator - the function called with the supplied key to create a new value; never null and must not return null
      Returns:
      the value; never null
      See Also:
    • computeIfAbsent

      public <K,V> V computeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator, Class<V> requiredType)
      Description copied from interface: Store
      Get the value of the specified required type that is stored under the supplied key.

      If no value is stored in this store for the supplied key, parent stores (if any) 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 or the value is null, a new value will be computed by the defaultCreator (given the key as input), stored, and returned.

      If the created value is an instance of AutoCloseable, then the close() method will be invoked on the stored object when the store is closed, unless documented otherwise by a subinterface.

      Specified by:
      computeIfAbsent in interface Store
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key; never null
      defaultCreator - the function called with the supplied key to create a new value; never null and must not return null
      requiredType - the required type of the value; never null
      Returns:
      the value; never null
      See Also:
    • put

      public void put(Object key, @Nullable Object value)
      Description copied from interface: Store
      Store a value for later retrieval under the supplied key.

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

      If the value is an instance of AutoCloseable, then the close() method will be invoked on the stored object when the store is closed, unless documented otherwise by a subinterface.

      Specified by:
      put in interface Store
      Parameters:
      key - the key under which the value should be stored; never null
      value - the value to store; may be null
      See Also:
    • remove

      public @Nullable Object remove(Object key)
      Description copied from interface: Store
      Remove the value that was previously stored under the supplied key.

      The value will only be removed in this store, not in parent stores. In addition, the AutoCloseable API will not be honored for values that are manually removed via this method.

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

      Specified by:
      remove in interface Store
      Parameters:
      key - the key; never null
      Returns:
      the previous value or null if no value was present for the specified key
      See Also:
    • remove

      public <T> @Nullable T remove(Object key, Class<T> requiredType)
      Description copied from interface: Store
      Remove the value of the specified required type that was previously stored under the supplied key.

      The value will only be removed in this store, not in parent stores. In addition, the AutoCloseable API will not be honored for values that are manually removed via this method.

      Specified by:
      remove in interface Store
      Type Parameters:
      T - the value type
      Parameters:
      key - the key; never null
      requiredType - the required type of the value; never null
      Returns:
      the previous value or null if no value was present for the specified key
      See Also: