Skip to content

Commit 2cb4713

Browse files
committed
Address review feedback by @sbrannen
1 parent a7e7a20 commit 2cb4713

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TimeoutConfiguration {
3939

4040
private final TimeoutDurationParser parser = new TimeoutDurationParser();
4141
private final Map<String, Optional<TimeoutDuration>> cache = new ConcurrentHashMap<>();
42-
private ExtensionContext extensionContext;
42+
private final ExtensionContext extensionContext;
4343

4444
TimeoutConfiguration(ExtensionContext extensionContext) {
4545
this.extensionContext = extensionContext;

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutExtension.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@ class TimeoutExtension implements BeforeAllCallback, BeforeEachCallback, Invocat
3737

3838
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(Timeout.class);
3939
private static final String TESTABLE_METHOD_TIMEOUT_KEY = "testable_method_timeout_from_annotation";
40+
private static final String GLOBAL_TIMEOUT_CONFIG_KEY = "global_timeout_config";
4041

4142
@Override
4243
public void beforeAll(ExtensionContext context) {
43-
readAndStoreTimeout(context);
44+
readAndStoreTimeoutSoChildrenInheritIt(context);
4445
}
4546

4647
@Override
4748
public void beforeEach(ExtensionContext context) {
48-
readAndStoreTimeout(context);
49+
readAndStoreTimeoutSoChildrenInheritIt(context);
50+
}
51+
52+
private void readAndStoreTimeoutSoChildrenInheritIt(ExtensionContext context) {
53+
readTimeoutFromAnnotation(context.getElement()).ifPresent(
54+
timeout -> context.getStore(NAMESPACE).put(TESTABLE_METHOD_TIMEOUT_KEY, timeout));
4955
}
5056

5157
@Override
@@ -97,11 +103,6 @@ public void interceptAfterAllMethod(Invocation<Void> invocation,
97103
TimeoutConfiguration::getDefaultAfterAllMethodTimeout);
98104
}
99105

100-
private void readAndStoreTimeout(ExtensionContext context) {
101-
readTimeoutFromAnnotation(context.getElement()).ifPresent(
102-
timeout -> context.getStore(NAMESPACE).put(TESTABLE_METHOD_TIMEOUT_KEY, timeout));
103-
}
104-
105106
private void interceptLifecycleMethod(Invocation<Void> invocation,
106107
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext,
107108
TimeoutProvider defaultTimeoutProvider) throws Throwable {
@@ -111,8 +112,8 @@ private void interceptLifecycleMethod(Invocation<Void> invocation,
111112
}
112113

113114
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
114-
private Optional<TimeoutDuration> readTimeoutFromAnnotation(Optional<AnnotatedElement> executable) {
115-
return AnnotationSupport.findAnnotation(executable, Timeout.class).map(TimeoutDuration::from);
115+
private Optional<TimeoutDuration> readTimeoutFromAnnotation(Optional<AnnotatedElement> element) {
116+
return AnnotationSupport.findAnnotation(element, Timeout.class).map(TimeoutDuration::from);
116117
}
117118

118119
private <T> T interceptTestableMethod(Invocation<T> invocation,
@@ -138,7 +139,7 @@ private TimeoutDuration getDefaultTimeout(ExtensionContext extensionContext,
138139

139140
private TimeoutConfiguration getGlobalTimeoutConfiguration(ExtensionContext extensionContext) {
140141
ExtensionContext root = extensionContext.getRoot();
141-
return root.getStore(NAMESPACE).getOrComputeIfAbsent("global_timeout_config",
142+
return root.getStore(NAMESPACE).getOrComputeIfAbsent(GLOBAL_TIMEOUT_CONFIG_KEY,
142143
key -> new TimeoutConfiguration(root), TimeoutConfiguration.class);
143144
}
144145

0 commit comments

Comments
 (0)