Top Description Inners Methods
org.junit.jupiter.api.extension

public Interface InvocationInterceptor

extends TestInstantiationAwareExtension
Annotations
@API
status:STABLE
since:5.10
Static Imports
org.apiguardian.api.API.Status.STABLE

InvocationInterceptor defines the API for Extensions that wish to intercept calls to test code.

Invocation Contract

Each method in this class must call Invocation#proceed() or Invocation#skip() exactly once on the supplied invocation. Otherwise, the enclosing test or container will be reported as failed.

The default implementation calls proceed() on the supplied invocation.

Constructor Requirements

Consult the documentation in Extension for details on constructor requirements.

ExtensionContext Scope

As of JUnit Jupiter 5.12, this API participates in the TestInstantiationAwareExtension contract. Implementations of this API may therefore choose to override getTestInstantiationExtensionContextScope(ExtensionContext). See interceptTestClassConstructor(Invocation, ReflectiveInvocationContext, ExtensionContext) for details.

Since
5.5
See Also
Invocation, ReflectiveInvocationContext, ExtensionContext

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
InvocationInterceptor.Invocation<
the result type
T extends @Nullable Object
>

An invocation that returns a result and may throw a Throwable.

Method Summary

Modifier and TypeMethod and Description
public default void
interceptAfterAllMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of an @AfterAll method.

public default void
interceptAfterEachMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of an @AfterEach method.

public default void
interceptBeforeAllMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a @BeforeAll method.

public default void
interceptBeforeEachMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a @BeforeEach method.

public default void
interceptDynamicTest(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
DynamicTestInvocationContext
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a DynamicTest.

public default <
the result type
T
>
T

Returns:

the result of the invocation; never null
interceptTestClassConstructor
(InvocationInterceptor.Invocation<T>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Constructor<T>>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a test class constructor.

public default <
the result type
T extends @Nullable Object
>
T

Returns:

the result of the invocation; potentially null
interceptTestFactoryMethod
(InvocationInterceptor.Invocation<T>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a @TestFactory method, such as a @RepeatedTest or @ParameterizedTest method.

public default void
interceptTestMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a @Test method.

public default void
interceptTestTemplateMethod(InvocationInterceptor.Invocation<@Nullable Void>
the invocation that is being intercepted; never null
invocation
,
ReflectiveInvocationContext<Method>
the context of the invocation that is being intercepted; never null
invocationContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a @TestTemplate method.

Inherited from org.junit.jupiter.api.extension.TestInstantiationAwareExtension:
getTestInstantiationExtensionContextScope

Method Detail

interceptAfterAllMethodback to summary
public default void interceptAfterAllMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of an @AfterAll method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
interceptAfterEachMethodback to summary
public default void interceptAfterEachMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of an @AfterEach method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
interceptBeforeAllMethodback to summary
public default void interceptBeforeAllMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @BeforeAll method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
interceptBeforeEachMethodback to summary
public default void interceptBeforeEachMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @BeforeEach method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
interceptDynamicTestback to summary
public default void interceptDynamicTest(InvocationInterceptor.Invocation<@Nullable Void> invocation, DynamicTestInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a DynamicTest.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:DynamicTestInvocationContext

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Annotations
@API
status:STABLE
since:5.11
Exceptions
Throwable:
in case of failures
interceptTestClassConstructorback to summary
public default <T> T interceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Constructor<T>> invocationContext, ExtensionContext extensionContext) throws 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 getTestInstantiationExtensionContextScope 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.

Parameters
<T>
the result type
invocation:InvocationInterceptor.Invocation<T>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Constructor<T>>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Returns:T

the result of the invocation; never null

Exceptions
Throwable:
in case of failure
interceptTestFactoryMethodback to summary
public default <T extends @Nullable Object> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @TestFactory method, such as a @RepeatedTest or @ParameterizedTest method.

Parameters
<T>
the result type
invocation:InvocationInterceptor.Invocation<T>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Returns:T

the result of the invocation; potentially null

Exceptions
Throwable:
in case of failures
interceptTestMethodback to summary
public default void interceptTestMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @Test method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
interceptTestTemplateMethodback to summary
public default void interceptTestTemplateMethod(InvocationInterceptor.Invocation<@Nullable Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @TestTemplate method.

Parameters
invocation:InvocationInterceptor.Invocation<@Nullable Void>

the invocation that is being intercepted; never null

invocationContext:ReflectiveInvocationContext<Method>

the context of the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Exceptions
Throwable:
in case of failures
org.junit.jupiter.api.extension back to summary

public Interface InvocationInterceptor.Invocation<T extends @Nullable Object>

Annotations
@API
status:STABLE
since:5.10
Type Parameters
<T>
the result type

An invocation that returns a result and may throw a Throwable.

This interface is not intended to be implemented by clients.

Since
5.5

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the result of this invocation; potentially null.
proceed
()

Proceed with this invocation.

public default void
skip()

Explicitly skip this invocation.

Method Detail

proceedback to summary
public T proceed() throws Throwable

Proceed with this invocation.

Returns:T

the result of this invocation; potentially null.

Exceptions
Throwable:
in case the invocation failed
skipback to summary
public default void skip()

Explicitly skip this invocation.

This allows to bypass the check that proceed() must be called at least once. The default implementation does nothing.

Annotations
@API
status:STABLE
since:5.10