Class ExtensionRegistry


  • public class ExtensionRegistry
    extends java.lang.Object
    Holds all found junit extensions for target context. Registry is hierarchical: first spec-level registry created and then feature-level registries. Extensions lookup performed by top-most registry and then by parent (if exists).

    Based on org.junit.jupiter.engine.extension.MutableExtensionRegistry from junit-jupiter-engine (5.8). Does not support auto-detected, default and synthetic extensions (no need).

    Since:
    30.11.2021
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <E extends org.junit.jupiter.api.extension.Extension>
      java.util.List<E>
      getExtensions​(java.lang.Class<E> extensionType)
      Get all Extensions of the specified type that are present in this registry or one of its ancestors.
      <E extends org.junit.jupiter.api.extension.Extension>
      java.util.List<E>
      getReversedExtensions​(java.lang.Class<E> extensionType)
      Get all Extensions of the specified type that are present in this registry or one of its ancestors, in reverse order.
      void registerExtension​(java.lang.Class<? extends org.junit.jupiter.api.extension.Extension> extensionType)
      Instantiate an extension of the given type using its default constructor and register it in the registry.
      void registerExtension​(org.junit.jupiter.api.extension.Extension extension, java.lang.Object source)
      Register the supplied Extension, without checking if an extension of that type has already been registered.
      <E extends org.junit.jupiter.api.extension.Extension>
      java.util.stream.Stream<E>
      stream​(java.lang.Class<E> extensionType)
      Stream all Extensions of the specified type that are present in this registry.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • stream

        public <E extends org.junit.jupiter.api.extension.Extension> java.util.stream.Stream<E> stream​(java.lang.Class<E> extensionType)
        Stream all Extensions of the specified type that are present in this registry.

        Extensions in ancestors are ignored.

        Type Parameters:
        E - extension type
        Parameters:
        extensionType - the type of Extension to stream
        Returns:
        stream of found extensions
        See Also:
        getReversedExtensions(Class)
      • getExtensions

        public <E extends org.junit.jupiter.api.extension.Extension> java.util.List<E> getExtensions​(java.lang.Class<E> extensionType)
        Get all Extensions of the specified type that are present in this registry or one of its ancestors.
        Type Parameters:
        E - extension type
        Parameters:
        extensionType - the type of Extension to get
        Returns:
        list of found extensions or empty list
        See Also:
        getReversedExtensions(Class), stream(Class)
      • getReversedExtensions

        public <E extends org.junit.jupiter.api.extension.Extension> java.util.List<E> getReversedExtensions​(java.lang.Class<E> extensionType)
        Get all Extensions of the specified type that are present in this registry or one of its ancestors, in reverse order.
        Type Parameters:
        E - extension type
        Parameters:
        extensionType - the type of Extension to get
        Returns:
        reversed list of found extensions
        See Also:
        getExtensions(Class), stream(Class)
      • registerExtension

        public void registerExtension​(java.lang.Class<? extends org.junit.jupiter.api.extension.Extension> extensionType)
        Instantiate an extension of the given type using its default constructor and register it in the registry.

        A new Extension should not be registered if an extension of the given type already exists in the registry or a parent registry.

        Parameters:
        extensionType - the type of extension to register
      • registerExtension

        public void registerExtension​(org.junit.jupiter.api.extension.Extension extension,
                                      java.lang.Object source)
        Register the supplied Extension, without checking if an extension of that type has already been registered.

        Semantics for Source

        If an extension is registered declaratively via @ExtendWith, the source and the extension should be the same object. However, if an extension is registered programmatically via @RegisterExtension, the source object should be the Field that is annotated with @RegisterExtension. Similarly, if an extension is registered programmatically as a lambda expression or method reference, the source object should be the underlying Method that implements the extension API.

        Parameters:
        extension - the extension to register; never null
        source - the source of the extension