Class TimeoutExtension
java.lang.Object
org.junit.jupiter.engine.extension.TimeoutExtension
- All Implemented Interfaces:
BeforeAllCallback
,BeforeEachCallback
,Extension
,InvocationInterceptor
class TimeoutExtension
extends Object
implements BeforeAllCallback, BeforeEachCallback, InvocationInterceptor
- Since:
- 5.5
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
InvocationInterceptor.Invocation<T>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeAll
(ExtensionContext context) Callback that is invoked once before all tests in the current container.void
beforeEach
(ExtensionContext context) Callback that is invoked before an individual test and any user-defined setup methods for that test have been executed.private <T> InvocationInterceptor.Invocation
<T> decorate
(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration timeout) private String
describe
(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) private Timeout.ThreadMode
getAnnotationThreadMode
(ExtensionContext extensionContext) private TimeoutDuration
getDefaultTimeout
(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) private TimeoutConfiguration
getGlobalTimeoutConfiguration
(ExtensionContext extensionContext) private <T> T
intercept
(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) void
interceptAfterAllMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterAll
method.void
interceptAfterEachMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterEach
method.void
interceptBeforeAllMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeAll
method.void
interceptBeforeEachMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeEach
method.private void
interceptLifecycleMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) private <T> T
interceptTestableMethod
(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) <T> T
interceptTestFactoryMethod
(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestFactory
method, such as a@RepeatedTest
or@ParameterizedTest
method.void
interceptTestMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@Test
method.void
interceptTestTemplateMethod
(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestTemplate
method.private boolean
isTimeoutDisabled
(String mode) Determine if timeouts are disabled for the supplied mode.private boolean
isTimeoutDisabled
(ExtensionContext extensionContext) Determine if timeouts are disabled for the supplied extension context.private void
private Optional
<TimeoutDuration> private Optional
<Timeout.ThreadMode> private Timeout.ThreadMode
resolveTimeoutThreadMode
(ExtensionContext extensionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor
-
Field Details
-
NAMESPACE
-
TESTABLE_METHOD_TIMEOUT_KEY
- See Also:
-
TESTABLE_METHOD_TIMEOUT_THREAD_MODE_KEY
- See Also:
-
GLOBAL_TIMEOUT_CONFIG_KEY
- See Also:
-
ENABLED_MODE_VALUE
- See Also:
-
DISABLED_MODE_VALUE
- See Also:
-
DISABLED_ON_DEBUG_MODE_VALUE
- See Also:
-
-
Constructor Details
-
TimeoutExtension
TimeoutExtension()
-
-
Method Details
-
beforeAll
Description copied from interface:BeforeAllCallback
Callback that is invoked once before all tests in the current container.- Specified by:
beforeAll
in interfaceBeforeAllCallback
- Parameters:
context
- the current extension context; nevernull
-
beforeEach
Description copied from interface:BeforeEachCallback
Callback that is invoked before an individual test and any user-defined setup methods for that test have been executed.- Specified by:
beforeEach
in interfaceBeforeEachCallback
- Parameters:
context
- the current extension context; nevernull
-
readAndStoreTimeoutSoChildrenInheritIt
-
interceptBeforeAllMethod
public void interceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of a@BeforeAll
method.- Specified by:
interceptBeforeAllMethod
in interfaceInvocationInterceptor
- 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
public void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of a@BeforeEach
method.- Specified by:
interceptBeforeEachMethod
in interfaceInvocationInterceptor
- 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
public void interceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of a@Test
method.- Specified by:
interceptTestMethod
in interfaceInvocationInterceptor
- 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
-
interceptTestTemplateMethod
public void interceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of a@TestTemplate
method.- Specified by:
interceptTestTemplateMethod
in interfaceInvocationInterceptor
- 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
public <T> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of a@TestFactory
method, such as a@RepeatedTest
or@ParameterizedTest
method.- Specified by:
interceptTestFactoryMethod
in interfaceInvocationInterceptor
- 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
-
interceptAfterEachMethod
public void interceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of an@AfterEach
method.- Specified by:
interceptAfterEachMethod
in interfaceInvocationInterceptor
- 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
public void interceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptor
Intercept the invocation of an@AfterAll
method.- Specified by:
interceptAfterAllMethod
in interfaceInvocationInterceptor
- 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
-
interceptLifecycleMethod
private void interceptLifecycleMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws Throwable - Throws:
Throwable
-
readTimeoutFromAnnotation
-
readTimeoutThreadModeFromAnnotation
private Optional<Timeout.ThreadMode> readTimeoutThreadModeFromAnnotation(Optional<AnnotatedElement> element) -
interceptTestableMethod
private <T> T interceptTestableMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws Throwable - Throws:
Throwable
-
intercept
private <T> T intercept(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws Throwable - Throws:
Throwable
-
getDefaultTimeout
private TimeoutDuration getDefaultTimeout(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) -
getGlobalTimeoutConfiguration
-
decorate
private <T> InvocationInterceptor.Invocation<T> decorate(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration timeout) -
resolveTimeoutThreadMode
-
getAnnotationThreadMode
-
describe
private String describe(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) -
isTimeoutDisabled
Determine if timeouts are disabled for the supplied extension context. -
isTimeoutDisabled
Determine if timeouts are disabled for the supplied mode.
-