Class TimeoutExtension
- java.lang.Object
-
- org.junit.jupiter.engine.extension.TimeoutExtension
-
- All Implemented Interfaces:
BeforeAllCallback,BeforeEachCallback,Extension,InvocationInterceptor
class TimeoutExtension extends java.lang.Object implements BeforeAllCallback, BeforeEachCallback, InvocationInterceptor
- Since:
- 5.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTimeoutExtension.ExecutorResourceprivate static interfaceTimeoutExtension.TimeoutProvider-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
InvocationInterceptor.Invocation<T>
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringDISABLED_MODE_VALUEprivate static java.lang.StringDISABLED_ON_DEBUG_MODE_VALUEprivate static java.lang.StringENABLED_MODE_VALUEprivate static java.lang.StringGLOBAL_TIMEOUT_CONFIG_KEYprivate static ExtensionContext.NamespaceNAMESPACEprivate static java.lang.StringTESTABLE_METHOD_TIMEOUT_KEY
-
Constructor Summary
Constructors Constructor Description TimeoutExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeforeAll(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<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration timeout)private java.lang.Stringdescribe(ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)private TimeoutDurationgetDefaultTimeout(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)private java.util.concurrent.ScheduledExecutorServicegetExecutor(ExtensionContext extensionContext)private TimeoutConfigurationgetGlobalTimeoutConfiguration(ExtensionContext extensionContext)private <T> Tintercept(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)voidinterceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of an@AfterAllmethod.voidinterceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of an@AfterEachmethod.voidinterceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@BeforeAllmethod.voidinterceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@BeforeEachmethod.private voidinterceptLifecycleMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)private <T> TinterceptTestableMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)<T> TinterceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@TestFactorymethod.voidinterceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@Testmethod.voidinterceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)Intercept the invocation of a@TestTemplatemethod.private booleanisTimeoutDisabled(java.lang.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 voidreadAndStoreTimeoutSoChildrenInheritIt(ExtensionContext context)private java.util.Optional<TimeoutDuration>readTimeoutFromAnnotation(java.util.Optional<java.lang.reflect.AnnotatedElement> element)-
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, interceptTestClassConstructor
-
-
-
-
Field Detail
-
NAMESPACE
private static final ExtensionContext.Namespace NAMESPACE
-
TESTABLE_METHOD_TIMEOUT_KEY
private static final java.lang.String TESTABLE_METHOD_TIMEOUT_KEY
- See Also:
- Constant Field Values
-
GLOBAL_TIMEOUT_CONFIG_KEY
private static final java.lang.String GLOBAL_TIMEOUT_CONFIG_KEY
- See Also:
- Constant Field Values
-
ENABLED_MODE_VALUE
private static final java.lang.String ENABLED_MODE_VALUE
- See Also:
- Constant Field Values
-
DISABLED_MODE_VALUE
private static final java.lang.String DISABLED_MODE_VALUE
- See Also:
- Constant Field Values
-
DISABLED_ON_DEBUG_MODE_VALUE
private static final java.lang.String DISABLED_ON_DEBUG_MODE_VALUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
beforeAll
public void beforeAll(ExtensionContext context)
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
public void beforeEach(ExtensionContext context)
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
private void readAndStoreTimeoutSoChildrenInheritIt(ExtensionContext context)
-
interceptBeforeAllMethod
public void interceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptBeforeEachMethod
public void interceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptTestMethod
public void interceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptTestTemplateMethod
public void interceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptTestFactoryMethod
public <T> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.Throwable
Description copied from interface:InvocationInterceptorIntercept the invocation of a@TestFactorymethod.- 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:
java.lang.Throwable- in case of failures
-
interceptAfterEachMethod
public void interceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptAfterAllMethod
public void interceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext) throws java.lang.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:
java.lang.Throwable- in case of failures
-
interceptLifecycleMethod
private void interceptLifecycleMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
readTimeoutFromAnnotation
private java.util.Optional<TimeoutDuration> readTimeoutFromAnnotation(java.util.Optional<java.lang.reflect.AnnotatedElement> element)
-
interceptTestableMethod
private <T> T interceptTestableMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
intercept
private <T> T intercept(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
getDefaultTimeout
private TimeoutDuration getDefaultTimeout(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)
-
getGlobalTimeoutConfiguration
private TimeoutConfiguration getGlobalTimeoutConfiguration(ExtensionContext extensionContext)
-
decorate
private <T> InvocationInterceptor.Invocation<T> decorate(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration timeout)
-
describe
private java.lang.String describe(ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
-
getExecutor
private java.util.concurrent.ScheduledExecutorService getExecutor(ExtensionContext extensionContext)
-
isTimeoutDisabled
private boolean isTimeoutDisabled(ExtensionContext extensionContext)
Determine if timeouts are disabled for the supplied extension context.
-
isTimeoutDisabled
private boolean isTimeoutDisabled(java.lang.String mode)
Determine if timeouts are disabled for the supplied mode.
-
-