@API(status=EXPERIMENTAL,
since="5.5")
public interface InvocationInterceptor
extends Extension
InvocationInterceptor defines the API for Extensions that wish to intercept calls to test code.
Each method in this class must execute the supplied invocation exactly once. Otherwise, the enclosing test or container will be reported as failed.
The default implementation simply calls proceed() on the supplied invocation.
Consult the documentation in Extension for details on
constructor requirements.
InvocationInterceptor.Invocation,
ReflectiveInvocationContext,
ExtensionContext| Modifier and Type | Interface and Description |
|---|---|
static interface |
InvocationInterceptor.Invocation<T>
An invocation that returns a result and may throw a
Throwable. |
| Modifier and Type | Method and Description |
|---|---|
default void |
interceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of an
@AfterAll method. |
default void |
interceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of an
@AfterEach method. |
default void |
interceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a
@BeforeAll method. |
default void |
interceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a
@BeforeEach method. |
default void |
interceptDynamicTest(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ExtensionContext extensionContext)
Intercept the invocation of a
DynamicTest. |
default <T> T |
interceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation,
ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a test class constructor.
|
default <T> T |
interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a
@TestFactory method. |
default void |
interceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a
@Test method. |
default void |
interceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation,
ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
ExtensionContext extensionContext)
Intercept the invocation of a
@TestTemplate method. |
default <T> T interceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
T - the result typeinvocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nullnulljava.lang.Throwable - in case of failuredefault void interceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@BeforeAll method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault void interceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@BeforeEach method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault void interceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@Test method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault <T> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@TestFactory method.T - the result typeinvocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nullnulljava.lang.Throwable - in case of failuresdefault void interceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@TestTemplate method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault void interceptDynamicTest(InvocationInterceptor.Invocation<java.lang.Void> invocation, ExtensionContext extensionContext) throws java.lang.Throwable
DynamicTest.invocation - the invocation that is being intercepted; never
nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault void interceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@AfterEach method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failuresdefault void interceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
@AfterAll method.invocation - the invocation that is being intercepted; never
nullinvocationContext - the context of the invocation that is being
intercepted; never nullextensionContext - the current extension context; never nulljava.lang.Throwable - in case of failures