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 ClassesModifier and TypeClassDescriptionprivate static classprivate static interfaceNested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
InvocationInterceptor.Invocation<T> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeAll(ExtensionContext context) Callback that is invoked once before all tests in the current container.voidbeforeEach(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 Stringdescribe(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) private TimeoutDurationgetDefaultTimeout(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) private ScheduledExecutorServicegetExecutor(ExtensionContext extensionContext) private TimeoutConfigurationgetGlobalTimeoutConfiguration(ExtensionContext extensionContext) private <T> Tintercept(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) voidinterceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterAllmethod.voidinterceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterEachmethod.voidinterceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeAllmethod.voidinterceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeEachmethod.private voidinterceptLifecycleMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) private <T> TinterceptTestableMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) <T> TinterceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestFactorymethod, such as a@RepeatedTestor@ParameterizedTestmethod.voidinterceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@Testmethod.voidinterceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestTemplatemethod.private booleanisTimeoutDisabled(String mode) Determine if timeouts are disabled for the supplied mode.private booleanisTimeoutDisabled(ExtensionContext extensionContext) Determine if timeouts are disabled for the supplied extension context.private voidprivate Optional<TimeoutDuration>Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor
-
Field Details
-
NAMESPACE
-
TESTABLE_METHOD_TIMEOUT_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:BeforeAllCallbackCallback that is invoked once before all tests in the current container.- Specified by:
beforeAllin interfaceBeforeAllCallback- Parameters:
context- the current extension context; nevernull
-
beforeEach
Description copied from interface:BeforeEachCallbackCallback that is invoked before an individual test and any user-defined setup methods for that test have been executed.- Specified by:
beforeEachin 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:InvocationInterceptorIntercept the invocation of a@BeforeAllmethod.- Specified by:
interceptBeforeAllMethodin interfaceInvocationInterceptor- 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:
Throwable- in case of failures
-
interceptBeforeEachMethod
public void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptorIntercept the invocation of a@BeforeEachmethod.- Specified by:
interceptBeforeEachMethodin interfaceInvocationInterceptor- 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:
Throwable- in case of failures
-
interceptTestMethod
public void interceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptorIntercept the invocation of a@Testmethod.- Specified by:
interceptTestMethodin interfaceInvocationInterceptor- 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:
Throwable- in case of failures
-
interceptTestTemplateMethod
public void interceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptorIntercept the invocation of a@TestTemplatemethod.- Specified by:
interceptTestTemplateMethodin interfaceInvocationInterceptor- 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:
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:InvocationInterceptorIntercept the invocation of a@TestFactorymethod, such as a@RepeatedTestor@ParameterizedTestmethod.- Specified by:
interceptTestFactoryMethodin interfaceInvocationInterceptor- 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:
Throwable- in case of failures
-
interceptAfterEachMethod
public void interceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptorIntercept the invocation of an@AfterEachmethod.- Specified by:
interceptAfterEachMethodin interfaceInvocationInterceptor- 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:
Throwable- in case of failures
-
interceptAfterAllMethod
public void interceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Description copied from interface:InvocationInterceptorIntercept the invocation of an@AfterAllmethod.- Specified by:
interceptAfterAllMethodin interfaceInvocationInterceptor- 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:
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
-
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) -
describe
private String describe(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) -
getExecutor
-
isTimeoutDisabled
Determine if timeouts are disabled for the supplied extension context. -
isTimeoutDisabled
Determine if timeouts are disabled for the supplied mode.
-