Class ExtensionUtils


  • final class ExtensionUtils
    extends java.lang.Object
    Collection of utilities for working with extensions and the extension registry.
    Since:
    5.1
    See Also:
    ExtensionRegistrar, MutableExtensionRegistry, ExtendWith, RegisterExtension
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Comparator<java.lang.reflect.Field> orderComparator  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExtensionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int getOrder​(java.lang.reflect.Field field)  
      (package private) static MutableExtensionRegistry populateNewExtensionRegistryFromExtendWithAnnotation​(MutableExtensionRegistry parentRegistry, java.lang.reflect.AnnotatedElement annotatedElement)
      Populate a new MutableExtensionRegistry from extension types declared via @ExtendWith on the supplied AnnotatedElement.
      (package private) static void registerExtensionsFromConstructorParameters​(ExtensionRegistrar registrar, java.lang.Class<?> clazz)
      Register extensions using the supplied registrar from parameters in the declared constructor of the supplied class that are annotated with @ExtendWith.
      (package private) static void registerExtensionsFromExecutableParameters​(ExtensionRegistrar registrar, java.lang.reflect.Executable executable)
      Register extensions using the supplied registrar from parameters in the supplied Executable (i.e., a Constructor or Method) that are annotated with @ExtendWith.
      (package private) static void registerExtensionsFromFields​(ExtensionRegistrar registrar, java.lang.Class<?> clazz, java.lang.Object instance)
      Register extensions using the supplied registrar from fields in the supplied class that are annotated with @ExtendWith or @RegisterExtension.
      private static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> streamExtensionTypes​(java.lang.reflect.AnnotatedElement annotatedElement)  
      private static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> streamExtensionTypes​(java.util.List<org.junit.jupiter.api.extension.ExtendWith> extendWithAnnotations)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • orderComparator

        private static final java.util.Comparator<java.lang.reflect.Field> orderComparator
        Since:
        5.4
    • Constructor Detail

      • ExtensionUtils

        private ExtensionUtils()
    • Method Detail

      • populateNewExtensionRegistryFromExtendWithAnnotation

        static MutableExtensionRegistry populateNewExtensionRegistryFromExtendWithAnnotation​(MutableExtensionRegistry parentRegistry,
                                                                                             java.lang.reflect.AnnotatedElement annotatedElement)
        Populate a new MutableExtensionRegistry from extension types declared via @ExtendWith on the supplied AnnotatedElement.
        Parameters:
        parentRegistry - the parent extension registry to set in the newly created registry; never null
        annotatedElement - the annotated element on which to search for declarations of @ExtendWith; never null
        Returns:
        the new extension registry; never null
        Since:
        5.0
      • registerExtensionsFromFields

        static void registerExtensionsFromFields​(ExtensionRegistrar registrar,
                                                 java.lang.Class<?> clazz,
                                                 java.lang.Object instance)
        Register extensions using the supplied registrar from 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 - the registrar with which to register the extensions; never null
        clazz - the class or interface in which to find the fields; never null
        instance - the instance of the supplied class; may be null when searching for static fields in the class
      • registerExtensionsFromConstructorParameters

        static void registerExtensionsFromConstructorParameters​(ExtensionRegistrar registrar,
                                                                java.lang.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 - the registrar with which to register the extensions; never null
        clazz - the class in which to find the declared constructor; never null
        Since:
        5.8
      • registerExtensionsFromExecutableParameters

        static void registerExtensionsFromExecutableParameters​(ExtensionRegistrar registrar,
                                                               java.lang.reflect.Executable executable)
        Register extensions using the supplied registrar from parameters in the supplied Executable (i.e., a Constructor or Method) that are annotated with @ExtendWith.
        Parameters:
        registrar - the registrar with which to register the extensions; never null
        executable - the constructor or method whose parameters should be searched; never null
        Since:
        5.8
      • streamExtensionTypes

        private static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> streamExtensionTypes​(java.lang.reflect.AnnotatedElement annotatedElement)
        Since:
        5.8
      • streamExtensionTypes

        private static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> streamExtensionTypes​(java.util.List<org.junit.jupiter.api.extension.ExtendWith> extendWithAnnotations)
        Since:
        5.8
      • getOrder

        private static int getOrder​(java.lang.reflect.Field field)
        Since:
        5.4