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 class
TimeoutExtension.ExecutorResource
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
GLOBAL_TIMEOUT_CONFIG_KEY
private static ExtensionContext.Namespace
NAMESPACE
private static java.lang.String
TESTABLE_METHOD_TIMEOUT_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 each test is invoked.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 TimeoutDuration
getDefaultTimeout(ExtensionContext extensionContext, TimeoutExtension.TimeoutProvider defaultTimeoutProvider)
private java.util.concurrent.ScheduledExecutorService
getExecutor(ExtensionContext extensionContext)
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.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 void
readAndStoreTimeoutSoChildrenInheritIt(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
-
-
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 each test is invoked.- 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.- 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)
-
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)
-
-