Package org.junit.jupiter.api.extension
Interface InvocationInterceptor
-
- All Superinterfaces:
Extension
@API(status=EXPERIMENTAL, since="5.5") public interface InvocationInterceptor extends ExtensionInvocationInterceptordefines the API forExtensionsthat wish to intercept calls to test code.Invocation Contract
Each method in this class must call
InvocationInterceptor.Invocation.proceed()orInvocationInterceptor.Invocation.skip()exactly once on the supplied invocation. 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
Extensionfor details on constructor requirements.- Since:
- 5.5
- See Also:
InvocationInterceptor.Invocation,ReflectiveInvocationContext,ExtensionContext
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceInvocationInterceptor.Invocation<T>An invocation that returns a result and may throw aThrowable.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidinterceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of an@AfterAllmethod.default voidinterceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of an@AfterEachmethod.default voidinterceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@BeforeAllmethod.default voidinterceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@BeforeEachmethod.default voidinterceptDynamicTest(InvocationInterceptor.Invocation<java.lang.Void> invocation, ExtensionContext extensionContext)Intercept the invocation of aDynamicTest.default <T> TinterceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a test class constructor.default <T> TinterceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@TestFactorymethod.default voidinterceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@Testmethod.default voidinterceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@TestTemplatemethod.
-
-
-
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.
- Type Parameters:
T- the result type- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@BeforeAllmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@BeforeEachmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@Testmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@TestFactorymethod.- Type Parameters:
T- the result type- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@TestTemplatemethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
java.lang.Throwable- in case of failures
-
interceptDynamicTest
default void interceptDynamicTest(InvocationInterceptor.Invocation<java.lang.Void> invocation, ExtensionContext extensionContext) throws java.lang.Throwable
Intercept the invocation of aDynamicTest.- Parameters:
invocation- the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@AfterEachmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- 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@AfterAllmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
java.lang.Throwable- in case of failures
-
-