Class ExtensionLifecycleMerger

  • All Implemented Interfaces:
    org.spockframework.runtime.extension.IMethodInterceptor

    public class ExtensionLifecycleMerger
    extends org.spockframework.runtime.extension.AbstractMethodInterceptor
    Merges junit extensions lifecycle into spock. Junit extensions executed before any other spock extensions (only other global spock extensions may be executed before, but they are almost never used).

    Implementation based on org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor and org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor from junit-jupiter-engine.

    NOTE: spock @Shared fields could not be supported as it would require duplicate beforeEach execution with different instances, which would probably break many junit extensions. As a result, @Shared fields would ALWAYS be null (because they are managed in a different instance - extension would not be able to initialize it in any case). This would produce ambiguous situations I can't detect. And so there is only one rule: nothing junit-specific should use @Shared annotation.

    Since:
    30.11.2021
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.spockframework.runtime.extension.IMethodInterceptor getFixtureMethodsInterceptor()
      Interceptor externalized in order to unify all interceptor registration in one place.
      MethodContext getMethodContext​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      ClassContext getSpecContext()  
      void interceptCleanupMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      void interceptCleanupSpecMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      void interceptFeatureMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      void interceptInitializerMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      void interceptSetupMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      void interceptSetupSpecMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)  
      • Methods inherited from class org.spockframework.runtime.extension.AbstractMethodInterceptor

        intercept, interceptDataProcessorMethod, interceptDataProviderMethod, interceptFeatureExecution, interceptIterationExecution, interceptSharedInitializerMethod, interceptSpecExecution
      • Methods inherited from class java.lang.Object

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

      • ExtensionLifecycleMerger

        public ExtensionLifecycleMerger​(ClassContext context)
    • Method Detail

      • getFixtureMethodsInterceptor

        public org.spockframework.runtime.extension.IMethodInterceptor getFixtureMethodsInterceptor()
        Interceptor externalized in order to unify all interceptor registration in one place.
        Returns:
        interceptor for fixture methods (setup/cleanup)
      • getSpecContext

        public ClassContext getSpecContext()
        Returns:
        spec-level context
      • getMethodContext

        public MethodContext getMethodContext​(org.spockframework.runtime.extension.IMethodInvocation invocation)
        Parameters:
        invocation - spock event
        Returns:
        method context
        Throws:
        java.lang.NullPointerException - when context not found
      • interceptSetupSpecMethod

        public void interceptSetupSpecMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                      throws java.lang.Throwable
        Overrides:
        interceptSetupSpecMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable
      • interceptInitializerMethod

        public void interceptInitializerMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                        throws java.lang.Throwable
        Overrides:
        interceptInitializerMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable
      • interceptSetupMethod

        public void interceptSetupMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                  throws java.lang.Throwable
        Overrides:
        interceptSetupMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable
      • interceptFeatureMethod

        public void interceptFeatureMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                    throws java.lang.Throwable
        Overrides:
        interceptFeatureMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable
      • interceptCleanupMethod

        public void interceptCleanupMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                    throws java.lang.Throwable
        Overrides:
        interceptCleanupMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable
      • interceptCleanupSpecMethod

        public void interceptCleanupSpecMethod​(org.spockframework.runtime.extension.IMethodInvocation invocation)
                                        throws java.lang.Throwable
        Overrides:
        interceptCleanupSpecMethod in class org.spockframework.runtime.extension.AbstractMethodInterceptor
        Throws:
        java.lang.Throwable