Class MutableExtensionRegistry
- All Implemented Interfaces:
ExtensionRegistrar
,ExtensionRegistry
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List
<org.junit.jupiter.api.extension.Extension> private static final org.junit.platform.commons.logging.Logger
private final MutableExtensionRegistry
private final List
<org.junit.jupiter.api.extension.Extension> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
buildSourceInfo
(Object source) static MutableExtensionRegistry
createRegistryFrom
(MutableExtensionRegistry parentRegistry, Stream<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 MutableExtensionRegistry
createRegistryWithDefaultExtensions
(JupiterConfiguration configuration) Factory for creating and populating a new root registry with the default extensions.private boolean
isAlreadyRegistered
(Class<? extends org.junit.jupiter.api.extension.Extension> extensionType) Determine if the supplied type is already registered in this registry or in a parent registry.private void
registerAutoDetectedExtension
(org.junit.jupiter.api.extension.Extension extension) private static void
registerAutoDetectedExtensions
(MutableExtensionRegistry extensionRegistry) private void
registerDefaultExtension
(org.junit.jupiter.api.extension.Extension extension) void
registerExtension
(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.private void
registerExtension
(String category, org.junit.jupiter.api.extension.Extension extension) private void
registerExtension
(String category, org.junit.jupiter.api.extension.Extension extension, Object source) void
registerExtension
(org.junit.jupiter.api.extension.Extension extension, Object source) Register the suppliedExtension
, without checking if an extension of that type has already been registered.private void
registerLocalExtension
(org.junit.jupiter.api.extension.Extension extension) void
registerSyntheticExtension
(org.junit.jupiter.api.extension.Extension extension, Object source) Register the suppliedExtension
as a synthetic extension, without checking if an extension of that type has already been registered.<E extends org.junit.jupiter.api.extension.Extension>
Stream<E> Stream allExtensions
of the specified type that are present in this registry or one of its ancestors.private <E extends org.junit.jupiter.api.extension.Extension>
Stream<E> streamLocal
(Class<E> extensionType) Stream allExtensions
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
Methods inherited from interface org.junit.jupiter.engine.extension.ExtensionRegistry
getExtensions
-
Field Details
-
logger
private static final org.junit.platform.commons.logging.Logger logger -
DEFAULT_STATELESS_EXTENSIONS
-
parent
-
registeredExtensionTypes
-
registeredExtensions
-
-
Constructor Details
-
MutableExtensionRegistry
-
-
Method Details
-
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 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
-
registerAutoDetectedExtensions
-
createRegistryFrom
public static MutableExtensionRegistry createRegistryFrom(MutableExtensionRegistry parentRegistry, Stream<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
-
stream
public <E extends org.junit.jupiter.api.extension.Extension> Stream<E> stream(Class<E> extensionType) Description copied from interface:ExtensionRegistry
Stream allExtensions
of the specified type that are present in this registry or one of its ancestors.- Specified by:
stream
in interfaceExtensionRegistry
- Parameters:
extensionType
- the type ofExtension
to stream- See Also:
-
streamLocal
private <E extends org.junit.jupiter.api.extension.Extension> Stream<E> streamLocal(Class<E> extensionType) Stream allExtensions
of the specified type that are present in this registry.Extensions in ancestors are ignored.
- Parameters:
extensionType
- the type ofExtension
to stream
-
registerExtension
public void registerExtension(Class<? extends org.junit.jupiter.api.extension.Extension> extensionType) Description copied from interface:ExtensionRegistrar
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.- Specified by:
registerExtension
in interfaceExtensionRegistrar
- Parameters:
extensionType
- the type of extension to register
-
isAlreadyRegistered
private boolean isAlreadyRegistered(Class<? extends org.junit.jupiter.api.extension.Extension> extensionType) Determine if the supplied type is already registered in this registry or in a parent registry. -
registerExtension
Description copied from interface:ExtensionRegistrar
Register the suppliedExtension
, without checking if an extension of that type has already been registered.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.- Specified by:
registerExtension
in interfaceExtensionRegistrar
- Parameters:
extension
- the extension to register; nevernull
source
- the source of the extension; nevernull
-
registerSyntheticExtension
public void registerSyntheticExtension(org.junit.jupiter.api.extension.Extension extension, Object source) Description copied from interface:ExtensionRegistrar
Register the suppliedExtension
as a synthetic extension, without checking if an extension of that type has already been registered.- Specified by:
registerSyntheticExtension
in interfaceExtensionRegistrar
- Parameters:
extension
- the extension to register; nevernull
source
- the source of the extension; nevernull
- See Also:
-
registerDefaultExtension
private void registerDefaultExtension(org.junit.jupiter.api.extension.Extension extension) -
registerAutoDetectedExtension
private void registerAutoDetectedExtension(org.junit.jupiter.api.extension.Extension extension) -
registerLocalExtension
private void registerLocalExtension(org.junit.jupiter.api.extension.Extension extension) -
registerExtension
private void registerExtension(String category, org.junit.jupiter.api.extension.Extension extension) -
registerExtension
-
buildSourceInfo
-