Class ExtensionRegistry
- java.lang.Object
-
- org.junit.jupiter.engine.extension.ExtensionRegistry
-
@API(status=INTERNAL, since="5.0") public class ExtensionRegistry extends java.lang.ObjectAnExtensionRegistryholds all registered extensions (i.e. instances ofExtension) for a givenNode.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.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ExtensionRegistrycreateRegistryFrom(ExtensionRegistry 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.static ExtensionRegistrycreateRegistryWithDefaultExtensions(org.junit.platform.engine.ConfigurationParameters configParams)Factory for creating and populating a new root registry with the default extensions.<E extends org.junit.jupiter.api.extension.Extension>
java.util.List<E>getExtensions(java.lang.Class<E> extensionType)Get allExtensionsof 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>getLocalExtensions(java.lang.Class<E> extensionType)Get allExtensionsof the specified type that are present in this registry, ignoring those present in one of its ancestors.ExtensionRegistrygetParent()Get the parent of thisExtensionRegistry.<E extends org.junit.jupiter.api.extension.Extension>
java.util.List<E>getReversedExtensions(java.lang.Class<E> extensionType)Get allExtensionsof the specified type that are present in this registry or one of its ancestors, in reverse order.voidregisterExtension(org.junit.jupiter.api.extension.Extension extension, java.lang.Object source)Register the suppliedExtensionin this registry, without checking if an extension of that type already exists in this registry.<E extends org.junit.jupiter.api.extension.Extension>
java.util.stream.Stream<E>stream(java.lang.Class<E> extensionType)Stream allExtensionsof the specified type that are present in this registry or one of its ancestors.
-
-
-
Method Detail
-
createRegistryWithDefaultExtensions
public static ExtensionRegistry createRegistryWithDefaultExtensions(org.junit.platform.engine.ConfigurationParameters configParams)
Factory for creating and populating a new root registry with the default extensions.If the
Constants.EXTENSIONS_AUTODETECTION_ENABLED_PROPERTY_NAMEconfiguration parameter has been set totrue, extensions will be auto-detected using Java'sServiceLoadermechanism and automatically registered after the default extensions.- Parameters:
configParams- configuration parameters used to retrieve the extension auto-detection flag; nevernull- Returns:
- a new
ExtensionRegistry; nevernull
-
createRegistryFrom
public static ExtensionRegistry createRegistryFrom(ExtensionRegistry 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 registryextensionTypes- the types of extensions to be registered in the new registry- Returns:
- a new
ExtensionRegistry; nevernull
-
getParent
public ExtensionRegistry getParent()
Get the parent of thisExtensionRegistry.WARNING: accessing the parent directly is typically unnecessary unless you are explicitly working with local extensions.
- Returns:
- the parent registry or
nullif no parent exists - Since:
- 5.3
-
stream
public <E extends org.junit.jupiter.api.extension.Extension> java.util.stream.Stream<E> stream(java.lang.Class<E> extensionType)
Stream allExtensionsof the specified type that are present in this registry or one of its ancestors.- Parameters:
extensionType- the type ofExtensionto stream- See Also:
getReversedExtensions(Class),getExtensions(Class)
-
getExtensions
public <E extends org.junit.jupiter.api.extension.Extension> java.util.List<E> getExtensions(java.lang.Class<E> extensionType)
Get allExtensionsof the specified type that are present in this registry or one of its ancestors.- Parameters:
extensionType- the type ofExtensionto get- See Also:
getLocalExtensions(Class),getReversedExtensions(Class),stream(Class)
-
getLocalExtensions
public <E extends org.junit.jupiter.api.extension.Extension> java.util.List<E> getLocalExtensions(java.lang.Class<E> extensionType)
Get allExtensionsof the specified type that are present in this registry, ignoring those present in one of its ancestors.WARNING: you typically need to invoke
getExtensions(Class)instead of this method.- Parameters:
extensionType- the type ofExtensionto get- Since:
- 5.3
- See Also:
getExtensions(Class),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 allExtensionsof the specified type that are present in this registry or one of its ancestors, in reverse order.- Parameters:
extensionType- the type ofExtensionto get- See Also:
getExtensions(Class),stream(Class)
-
registerExtension
public void registerExtension(org.junit.jupiter.api.extension.Extension extension, java.lang.Object source)Register the suppliedExtensionin this registry, without checking if an extension of that type already exists in this registry.Semantics for Source
If an extension is registered declaratively via
@ExtendWith, thesourceand theextensionshould be the same object. However, if an extension is registered programmatically via@RegisterExtension, thesourceobject should be theFieldthat is annotated with@RegisterExtension. Similarly, if an extension is registered programmatically as a lambda expression or method reference, thesourceobject should be the underlyingMethodthat implements the extension API.- Parameters:
extension- the extension to registersource- the source of the extension
-
-