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

public Interface InvocationInterceptor

extends Extension
Annotations
@API
status:STABLE
since:5.10
Static Imports
org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .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.

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
>

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

Method Summary

Modifier and TypeMethod and Description
public default void
interceptAfterAllMethod(InvocationInterceptor.Invocation<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<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<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<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<Void>
the invocation that is being intercepted; never null
invocation
,
ExtensionContext
the current extension context; never null
extensionContext
)

Intercept the invocation of a DynamicTest.
public default void
interceptDynamicTest(InvocationInterceptor.Invocation<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
>
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<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<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.

Method Detail

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

Intercept the invocation of an @AfterAll method.

Parameters
invocation:InvocationInterceptor.Invocation<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<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of an @AfterEach method.

Parameters
invocation:InvocationInterceptor.Invocation<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<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @BeforeAll method.

Parameters
invocation:InvocationInterceptor.Invocation<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<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @BeforeEach method.

Parameters
invocation:InvocationInterceptor.Invocation<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<Void> invocation, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a DynamicTest.

Parameters
invocation:InvocationInterceptor.Invocation<Void>

the invocation that is being intercepted; never null

extensionContext:ExtensionContext

the current extension context; never null

Annotations
@Deprecated
@API
status:DEPRECATED
since:5.8
Exceptions
Throwable:
in case of failures
interceptDynamicTestback to summary
public default void interceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, DynamicTestInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a DynamicTest.

Parameters
invocation:InvocationInterceptor.Invocation<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:EXPERIMENTAL
since:5.8
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.

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> 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<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @Test method.

Parameters
invocation:InvocationInterceptor.Invocation<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<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable

Intercept the invocation of a @TestTemplate method.

Parameters
invocation:InvocationInterceptor.Invocation<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>

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