Class ExtensionRegistry
- java.lang.Object
-
- org.junit.jupiter.engine.extension.ExtensionRegistry
-
@API(status=INTERNAL, since="5.0") public class ExtensionRegistry extends Object
AnExtensionRegistry
holds 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 ExtensionRegistry
createRegistryFrom(ExtensionRegistry parentRegistry, List<Class<? extends Extension>> extensionTypes)
Factory for creating and populating a new registry from a list of extension types and a parent registry.static ExtensionRegistry
createRegistryWithDefaultExtensions(JupiterConfiguration configuration)
Factory for creating and populating a new root registry with the default extensions.<E extends Extension>
List<E>getExtensions(Class<E> extensionType)
Get allExtensions
of the specified type that are present in this registry or one of its ancestors.<E extends Extension>
List<E>getReversedExtensions(Class<E> extensionType)
Get allExtensions
of the specified type that are present in this registry or one of its ancestors, in reverse order.void
registerExtension(Extension extension, Object source)
Register the suppliedExtension
in this registry, without checking if an extension of that type already exists in this registry.<E extends Extension>
Stream<E>stream(Class<E> extensionType)
Stream allExtensions
of the specified type that are present in this registry or one of its ancestors.
-
-
-
Method Detail
-
createRegistryWithDefaultExtensions
public static ExtensionRegistry 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 totrue
, extensions will be auto-detected using Java'sServiceLoader
mechanism and automatically registered after the default extensions.- Parameters:
configuration
- configuration parameters used to retrieve the extension auto-detection flag; nevernull
- Returns:
- a new
ExtensionRegistry
; nevernull
-
createRegistryFrom
public static ExtensionRegistry createRegistryFrom(ExtensionRegistry parentRegistry, List<Class<? extends 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
-
stream
public <E extends Extension> Stream<E> stream(Class<E> extensionType)
Stream allExtensions
of the specified type that are present in this registry or one of its ancestors.- Parameters:
extensionType
- the type ofExtension
to stream- See Also:
getReversedExtensions(Class)
,getExtensions(Class)
-
getExtensions
public <E extends Extension> List<E> getExtensions(Class<E> extensionType)
Get allExtensions
of the specified type that are present in this registry or one of its ancestors.- Parameters:
extensionType
- the type ofExtension
to get- See Also:
getReversedExtensions(Class)
,stream(Class)
-
getReversedExtensions
public <E extends Extension> List<E> getReversedExtensions(Class<E> extensionType)
Get allExtensions
of the specified type that are present in this registry or one of its ancestors, in reverse order.- Parameters:
extensionType
- the type ofExtension
to get- See Also:
getExtensions(Class)
,stream(Class)
-
registerExtension
public void registerExtension(Extension extension, Object source)
Register the suppliedExtension
in 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
, thesource
and theextension
should be the same object. However, if an extension is registered programmatically via@RegisterExtension
, thesource
object should be theField
that is annotated with@RegisterExtension
. Similarly, if an extension is registered programmatically as a lambda expression or method reference, thesource
object should be the underlyingMethod
that implements the extension API.- Parameters:
extension
- the extension to registersource
- the source of the extension
-
-