Interface InvocationInterceptor

    • Method Detail

      • interceptTestClassConstructor

        default <T> T interceptTestClassConstructor​(InvocationInterceptor.Invocation<T> invocation,
                                                    ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext,
                                                    ExtensionContext extensionContext)
                                             throws java.lang.Throwable
        Intercept the invocation of a test class constructor.

        Note that the test class may not have been initialized (static initialization) when this method is invoked.

        By default, the supplied ExtensionContext represents the test class that's about to be constructed. Extensions may override TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope(org.junit.jupiter.api.extension.ExtensionContext) to return TEST_METHOD in order to change the scope of the ExtensionContext to the test method, unless the PER_CLASS lifecycle is used. Changing the scope makes test-specific data available to the implementation of this method and allows keeping state on the test level by using the provided Store instance.

        Type Parameters:
        T - the result type
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Returns:
        the result of the invocation; never null
        Throws:
        java.lang.Throwable - in case of failure
      • interceptBeforeAllMethod

        default void interceptBeforeAllMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                              ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                              ExtensionContext extensionContext)
                                       throws java.lang.Throwable
        Intercept the invocation of a @BeforeAll method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptBeforeEachMethod

        default void interceptBeforeEachMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                               ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                               ExtensionContext extensionContext)
                                        throws java.lang.Throwable
        Intercept the invocation of a @BeforeEach method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptTestMethod

        default void interceptTestMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                         ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                         ExtensionContext extensionContext)
                                  throws java.lang.Throwable
        Intercept the invocation of a @Test method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptTestFactoryMethod

        default <T> T interceptTestFactoryMethod​(InvocationInterceptor.Invocation<T> invocation,
                                                 ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                                 ExtensionContext extensionContext)
                                          throws java.lang.Throwable
        Intercept the invocation of a @TestFactory method, such as a @RepeatedTest or @ParameterizedTest method.
        Type Parameters:
        T - the result type
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Returns:
        the result of the invocation; potentially null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptTestTemplateMethod

        default void interceptTestTemplateMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                                 ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                                 ExtensionContext extensionContext)
                                          throws java.lang.Throwable
        Intercept the invocation of a @TestTemplate method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptDynamicTest

        @API(status=STABLE,
             since="5.11")
        default void interceptDynamicTest​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                          DynamicTestInvocationContext invocationContext,
                                          ExtensionContext extensionContext)
                                   throws java.lang.Throwable
        Intercept the invocation of a DynamicTest.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptAfterEachMethod

        default void interceptAfterEachMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                              ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                              ExtensionContext extensionContext)
                                       throws java.lang.Throwable
        Intercept the invocation of an @AfterEach method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures
      • interceptAfterAllMethod

        default void interceptAfterAllMethod​(InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                             ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                             ExtensionContext extensionContext)
                                      throws java.lang.Throwable
        Intercept the invocation of an @AfterAll method.
        Parameters:
        invocation - the invocation that is being intercepted; never null
        invocationContext - the context of the invocation that is being intercepted; never null
        extensionContext - the current extension context; never null
        Throws:
        java.lang.Throwable - in case of failures