Class MutableExtensionRegistry

  • All Implemented Interfaces:
    ExtensionRegistrar, ExtensionRegistry

    @API(status=INTERNAL,
         since="5.5")
    public class MutableExtensionRegistry
    extends java.lang.Object
    implements ExtensionRegistry, ExtensionRegistrar
    Default, mutable implementation of ExtensionRegistry.

    A registry has a reference to its parent registry, and all lookups are performed first in the current registry itself and then recursively in its ancestors.

    Since:
    5.5
    • Method Detail

      • createRegistryWithDefaultExtensions

        public static MutableExtensionRegistry createRegistryWithDefaultExtensions​(JupiterConfiguration configuration)
        Factory for creating and populating a new root registry with the default extensions.

        If the Constants.EXTENSIONS_AUTODETECTION_ENABLED_PROPERTY_NAME configuration parameter has been set to true, extensions will be auto-detected using Java's ServiceLoader mechanism and automatically registered after the default extensions.

        Parameters:
        configuration - configuration parameters used to retrieve the extension auto-detection flag; never null
        Returns:
        a new ExtensionRegistry; never null
      • createRegistryFrom

        public static MutableExtensionRegistry createRegistryFrom​(MutableExtensionRegistry parentRegistry,
                                                                  java.util.List<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> extensionTypes)
        Factory for creating and populating a new registry from a list of extension types and a parent registry.
        Parameters:
        parentRegistry - the parent registry
        extensionTypes - the types of extensions to be registered in the new registry
        Returns:
        a new ExtensionRegistry; never null
      • registerExtension

        public void registerExtension​(org.junit.jupiter.api.extension.Extension extension,
                                      java.lang.Object source)
        Description copied from interface: ExtensionRegistrar
        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.

        Specified by:
        registerExtension in interface ExtensionRegistrar
        Parameters:
        extension - the extension to register; never null
        source - the source of the extension; never null