Package org.junit.jupiter.api.extension
Interface InvocationInterceptor
-
- All Superinterfaces:
Extension
@API(status=EXPERIMENTAL, since="5.5") public interface InvocationInterceptor extends Extension
InvocationInterceptor
defines the API forExtensions
that wish to intercept calls to test code.Invocation Contract
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.Constructor Requirements
Consult the documentation in
Extension
for details on constructor requirements.- Since:
- 5.5
- See Also:
InvocationInterceptor.Invocation
,ReflectiveInvocationContext
,ExtensionContext
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
InvocationInterceptor.Invocation<T>
An invocation that returns a result and may throw aThrowable
.
-
Method Summary
-
-
-
Method Detail
-
interceptTestClassConstructor
default <T> T interceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Constructor<T>> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a test class constructor.- Type Parameters:
T
- the result type- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Returns:
- the result of the invocation; never
null
- Throws:
Throwable
- in case of failure
-
interceptBeforeAllMethod
default void interceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a@BeforeAll
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptBeforeEachMethod
default void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a@BeforeEach
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptTestMethod
default void interceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a@Test
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptTestFactoryMethod
default <T> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a@TestFactory
method.- Type Parameters:
T
- the result type- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Returns:
- the result of the invocation; potentially
null
- Throws:
Throwable
- in case of failures
-
interceptTestTemplateMethod
default void interceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of a@TestTemplate
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptDynamicTest
default void interceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of aDynamicTest
.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptAfterEachMethod
default void interceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of an@AfterEach
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
interceptAfterAllMethod
default void interceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable
Intercept the invocation of an@AfterAll
method.- Parameters:
invocation
- the invocation that is being intercepted; nevernull
invocationContext
- the context of the invocation that is being intercepted; nevernull
extensionContext
- the current extension context; nevernull
- Throws:
Throwable
- in case of failures
-
-