Class ExtensionUtils


  • public final class ExtensionUtils
    extends java.lang.Object
    Extensions recognition logic. Mostly copy of jupiter implementation methods (with slight adoptions) to preserve exactly the same behaviour. Started as a subset of org.junit.jupiter.engine.descriptor.ExtensionUtils, but also include some descriptors logic (descriptors concept itself is not required in spock context).
    Since:
    30.11.2021
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.List<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> SUPPORTED_EXTENSIONS  
      static java.util.List<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> UNSUPPORTED_EXTENSIONS  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String asLabel​(java.lang.reflect.Executable executable)  
      static ExtensionRegistry createMethodRegistry​(ExtensionRegistry root, java.lang.reflect.Method method)  
      static ExtensionRegistry createRegistry​(java.lang.Class<?> testClass)  
      static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> findClassExtensions​(java.lang.Class<?> testClass)  
      static void registerExtensionsFromExecutableParameters​(ExtensionRegistry 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.
      static void registerExtensionsFromFields​(ExtensionRegistry 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.
      static java.lang.Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext, java.lang.reflect.Executable executable, AbstractContext context)  
      • Methods inherited from class java.lang.Object

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

      • SUPPORTED_EXTENSIONS

        public static final java.util.List<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> SUPPORTED_EXTENSIONS
      • UNSUPPORTED_EXTENSIONS

        public static final java.util.List<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> UNSUPPORTED_EXTENSIONS
    • Method Detail

      • createRegistry

        public static ExtensionRegistry createRegistry​(java.lang.Class<?> testClass)
      • findClassExtensions

        public static java.util.stream.Stream<java.lang.Class<? extends org.junit.jupiter.api.extension.Extension>> findClassExtensions​(java.lang.Class<?> testClass)
      • registerExtensionsFromFields

        public static void registerExtensionsFromFields​(ExtensionRegistry 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
      • registerExtensionsFromExecutableParameters

        public static void registerExtensionsFromExecutableParameters​(ExtensionRegistry 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
      • resolveParameter

        public static java.lang.Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                                        java.lang.reflect.Executable executable,
                                                        AbstractContext context)
      • asLabel

        public static java.lang.String asLabel​(java.lang.reflect.Executable executable)
        Parameters:
        executable - executable
        Returns:
        correct executable name