- 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 interface
TimeoutExtension.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.String
DISABLED_MODE_VALUE
private static java.lang.String
DISABLED_ON_DEBUG_MODE_VALUE
private static java.lang.String
ENABLED_MODE_VALUE
private static java.lang.String
GLOBAL_TIMEOUT_CONFIG_KEY
private static ExtensionContext.Namespace
NAMESPACE
private static java.lang.String
TESTABLE_METHOD_TIMEOUT_KEY
private static java.lang.String
TESTABLE_METHOD_TIMEOUT_THREAD_MODE_KEY
-
Constructor Summary
Constructors Constructor Description TimeoutExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration timeout)
private java.lang.String
describe(ReflectiveInvocationContext<java.lang.reflect.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<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutDuration explicitTimeout, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)
void
interceptAfterAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of an@AfterAll
method.void
interceptAfterEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of an@AfterEach
method.void
interceptBeforeAllMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of a@BeforeAll
method.void
interceptBeforeEachMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of a@BeforeEach
method.private void
interceptLifecycleMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)
private <T> T
interceptTestableMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)
<T> T
interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of a@TestFactory
method, such as a@RepeatedTest
or@ParameterizedTest
method.void
interceptTestMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of a@Test
method.void
interceptTestTemplateMethod(InvocationInterceptor.Invocation<java.lang.Void> invocation, ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, ExtensionContext extensionContext)
Intercept the invocation of a@TestTemplate
method.private boolean
isTimeoutDisabled(java.lang.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
readAndStoreTimeoutSoChildrenInheritIt(ExtensionContext context)
private java.util.Optional<TimeoutDuration>
readTimeoutFromAnnotation(java.util.Optional<java.lang.reflect.AnnotatedElement> element)
private java.util.Optional<Timeout.ThreadMode>
readTimeoutThreadModeFromAnnotation(java.util.Optional<java.lang.reflect.AnnotatedElement> element)
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 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
-
TESTABLE_METHOD_TIMEOUT_THREAD_MODE_KEY
private static final java.lang.String TESTABLE_METHOD_TIMEOUT_THREAD_MODE_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: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
public void beforeEach(ExtensionContext context)
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
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: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:
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: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:
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: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:
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: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:
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: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:
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: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:
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: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:
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)
-
readTimeoutThreadModeFromAnnotation
private java.util.Optional<Timeout.ThreadMode> readTimeoutThreadModeFromAnnotation(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)
-
resolveTimeoutThreadMode
private Timeout.ThreadMode resolveTimeoutThreadMode(ExtensionContext extensionContext)
-
getAnnotationThreadMode
private Timeout.ThreadMode getAnnotationThreadMode(ExtensionContext extensionContext)
-
describe
private java.lang.String describe(ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, 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.
-
-