Top Description Fields Constructors Methods
org.junit.jupiter.engine.descriptor

pack-priv final Class ExtensionUtils

extends Object
Class Inheritance
Static Imports
java.util.stream.Collectors.toList, org.junit.platform.commons.support.AnnotationSupport.findAnnotation, .AnnotationSupport.isAnnotated, org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations, .ReflectionUtils.HierarchyTraversalMode.TOP_DOWN, .ReflectionUtils.getDeclaredConstructor, .ReflectionUtils.streamFields, .ReflectionUtils.tryToReadFieldValue

Collection of utilities for working with extensions and the extension registry.
Since
5.1
See Also
ExtensionRegistrar, MutableExtensionRegistry, ExtendWith, RegisterExtension

Field Summary

Modifier and TypeField and Description
private static final Comparator<Field>
private static final Predicate<Field>
registersExtension

Predicate which determines if a Field registers an extension via @RegisterExtension or @ExtendWith.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
getOrder(Field field)

pack-priv static MutableExtensionRegistry

Returns:

the new extension registry; never null
populateNewExtensionRegistryFromExtendWithAnnotation
(MutableExtensionRegistry
the parent extension registry to set in the newly created registry; never null
parentRegistry
,
AnnotatedElement
the annotated element on which to search for declarations of @ExtendWith; never null
annotatedElement
)

Populate a new MutableExtensionRegistry from extension types declared via @ExtendWith on the supplied AnnotatedElement.

private static Extension
readAndValidateExtensionFromField(Field field, @Nullable Object instance, List<Class<? extends Extension>> declarativeExtensionTypes)

pack-priv static void
registerExtensionsFromConstructorParameters(ExtensionRegistrar
the registrar with which to register the extensions; never null
registrar
,
Class<?>
the class in which to find the declared constructor; never null
clazz
)

Register extensions using the supplied registrar from parameters in the declared constructor of the supplied class that are annotated with @ExtendWith.

pack-priv static void
registerExtensionsFromExecutableParameters(ExtensionRegistrar
the registrar with which to register the extensions; never null
registrar
,
Executable
the constructor or method whose parameters should be searched; never null
executable
)

Register extensions using the supplied registrar from parameters in the supplied Executable (i.e., a java.lang.reflect.Constructor or java.lang.reflect.Method) that are annotated with @ExtendWith.

pack-priv static void
registerExtensionsFromInstanceFields(ExtensionRegistrar
the registrar with which to register the extensions; never null
registrar
,
Class<?>
the class or interface in which to find the fields; never null
clazz
)

Register extensions using the supplied registrar from instance fields in the supplied class that are annotated with @ExtendWith or @RegisterExtension.

pack-priv static void
registerExtensionsFromStaticFields(ExtensionRegistrar
the registrar with which to register the extensions; never null
registrar
,
Class<?>
the class or interface in which to find the fields; never null
clazz
)

Register extensions using the supplied registrar from static fields in the supplied class that are annotated with @ExtendWith or @RegisterExtension.

private static Stream<Class<? extends Extension>>
private static Stream<Class<? extends Extension>>
private static Stream<Field>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderComparatorback to summary
private static final Comparator<Field> orderComparator
Since
5.4
registersExtensionback to summary
private static final Predicate<Field> registersExtension

Predicate which determines if a Field registers an extension via @RegisterExtension or @ExtendWith.

Since
5.11.3

Constructor Detail

ExtensionUtilsback to summary
private ExtensionUtils()

Method Detail

getOrderback to summary
private static int getOrder(Field field)
Since
5.4
populateNewExtensionRegistryFromExtendWithAnnotationback to summary
pack-priv static MutableExtensionRegistry populateNewExtensionRegistryFromExtendWithAnnotation(MutableExtensionRegistry parentRegistry, AnnotatedElement annotatedElement)

Populate a new MutableExtensionRegistry from extension types declared via @ExtendWith on the supplied AnnotatedElement.

Parameters
parentRegistry:MutableExtensionRegistry

the parent extension registry to set in the newly created registry; never null

annotatedElement:AnnotatedElement

the annotated element on which to search for declarations of @ExtendWith; never null

Returns:MutableExtensionRegistry

the new extension registry; never null

Since
5.0
readAndValidateExtensionFromFieldback to summary
private static Extension readAndValidateExtensionFromField(Field field, @Nullable Object instance, List<Class<? extends Extension>> declarativeExtensionTypes)
Since
5.11
registerExtensionsFromConstructorParametersback to summary
pack-priv static void registerExtensionsFromConstructorParameters(ExtensionRegistrar registrar, Class<?> clazz)

Register extensions using the supplied registrar from parameters in the declared constructor of the supplied class that are annotated with @ExtendWith.

Parameters
registrar:ExtensionRegistrar

the registrar with which to register the extensions; never null

clazz:Class<?>

the class in which to find the declared constructor; never null

Since
5.8
registerExtensionsFromExecutableParametersback to summary
pack-priv static void registerExtensionsFromExecutableParameters(ExtensionRegistrar registrar, Executable executable)

Register extensions using the supplied registrar from parameters in the supplied Executable (i.e., a java.lang.reflect.Constructor or java.lang.reflect.Method) that are annotated with @ExtendWith.

Parameters
registrar:ExtensionRegistrar

the registrar with which to register the extensions; never null

executable:Executable

the constructor or method whose parameters should be searched; never null

Since
5.8
registerExtensionsFromInstanceFieldsback to summary
pack-priv static void registerExtensionsFromInstanceFields(ExtensionRegistrar registrar, Class<?> clazz)

Register extensions using the supplied registrar from instance fields in the supplied class that are annotated with @ExtendWith or @RegisterExtension.

The extensions will be sorted according to @Order semantics prior to registration.

Parameters
registrar:ExtensionRegistrar

the registrar with which to register the extensions; never null

clazz:Class<?>

the class or interface in which to find the fields; never null

Since
5.11
registerExtensionsFromStaticFieldsback to summary
pack-priv static void registerExtensionsFromStaticFields(ExtensionRegistrar registrar, Class<?> clazz)

Register extensions using the supplied registrar from static fields in the supplied class that are annotated with @ExtendWith or @RegisterExtension.

The extensions will be sorted according to @Order semantics prior to registration.

Parameters
registrar:ExtensionRegistrar

the registrar with which to register the extensions; never null

clazz:Class<?>

the class or interface in which to find the fields; never null

Since
5.11
streamDeclarativeExtensionTypesback to summary
private static Stream<Class<? extends Extension>> streamDeclarativeExtensionTypes(AnnotatedElement annotatedElement)
Since
5.11
streamDeclarativeExtensionTypesback to summary
private static Stream<Class<? extends Extension>> streamDeclarativeExtensionTypes(List<ExtendWith> extendWithAnnotations)
Since
5.11
streamExtensionRegisteringFieldsback to summary
private static Stream<Field> streamExtensionRegisteringFields(Class<?> clazz, Predicate<Field> predicate)
Since
5.11