Skip to content

Commit e8820eb

Browse files
committed
Move timezoine to API
1 parent f11b8e9 commit e8820eb

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* https://www.eclipse.org/legal/epl-v20.html
99
*/
1010

11-
package org.junit.jupiter.engine.extension;
11+
package org.junit.jupiter.api.util;
1212

1313
import java.lang.reflect.AnnotatedElement;
1414
import java.util.Optional;
@@ -20,8 +20,6 @@
2020
import org.junit.jupiter.api.extension.ExtensionContext;
2121
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
2222
import org.junit.jupiter.api.extension.ExtensionContext.Store;
23-
import org.junit.jupiter.api.util.DefaultTimeZone;
24-
import org.junit.jupiter.api.util.TimeZoneProvider;
2523
import org.junit.jupiter.api.util.TimeZoneProvider.NullTimeZoneProvider;
2624
import org.junit.platform.commons.support.AnnotationSupport;
2725
import org.junit.platform.commons.support.ReflectionSupport;
@@ -36,7 +34,7 @@ class DefaultTimeZoneExtension implements BeforeEachCallback, AfterEachCallback
3634
public void beforeEach(ExtensionContext context) {
3735
AnnotatedElement element = context.getElement().orElse(null);
3836
AnnotationSupport.findAnnotation(element, DefaultTimeZone.class).ifPresent(
39-
annotation -> setDefaultTimeZone(context.getStore(NAMESPACE), annotation));
37+
annotation -> setDefaultTimeZone(context.getStore(NAMESPACE), annotation));
4038
}
4139

4240
private void setDefaultTimeZone(Store store, DefaultTimeZone annotation) {
@@ -58,8 +56,7 @@ private static void validateCorrectConfiguration(DefaultTimeZone annotation) {
5856
boolean noProvider = annotation.timeZoneProvider() == NullTimeZoneProvider.class;
5957
if (noValue == noProvider)
6058
throw new ExtensionConfigurationException(
61-
"Either a valid time zone id or a TimeZoneProvider must be provided to "
62-
+ DefaultTimeZone.class.getSimpleName());
59+
"Either a valid time zone id or a TimeZoneProvider must be provided to " + DefaultTimeZone.class.getSimpleName());
6360
}
6461

6562
private static TimeZone createTimeZone(String timeZoneId) {
@@ -82,7 +79,7 @@ private static TimeZone createTimeZone(Class<? extends TimeZoneProvider> provide
8279
}
8380
catch (Exception exception) {
8481
throw new ExtensionConfigurationException("Could not instantiate TimeZoneProvider because of exception",
85-
exception);
82+
exception);
8683
}
8784
}
8885

@@ -94,7 +91,7 @@ private void storeDefaultTimeZone(Store store) {
9491
public void afterEach(ExtensionContext context) {
9592
AnnotatedElement element = context.getElement().orElse(null);
9693
AnnotationSupport.findAnnotation(element, DefaultTimeZone.class).ifPresent(
97-
__ -> resetDefaultTimeZone(context.getStore(NAMESPACE)));
94+
__ -> resetDefaultTimeZone(context.getStore(NAMESPACE)));
9895
}
9996

10097
private void resetDefaultTimeZone(Store store) {

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public class MutableExtensionRegistry implements ExtensionRegistry, ExtensionReg
5151
private static final Logger logger = LoggerFactory.getLogger(MutableExtensionRegistry.class);
5252

5353
private static final List<Extension> DEFAULT_STATELESS_EXTENSIONS = List.of( //
54-
new DisabledCondition(), //
55-
new AutoCloseExtension(), //
56-
new TimeoutExtension(), //
57-
new RepeatedTestExtension(), //
58-
new TestInfoParameterResolver(), //
59-
new TestReporterParameterResolver() //
54+
new DisabledCondition(), //
55+
new AutoCloseExtension(), //
56+
new TimeoutExtension(), //
57+
new RepeatedTestExtension(), //
58+
new TestInfoParameterResolver(), //
59+
new TestReporterParameterResolver() //
6060
);
6161

6262
/**
@@ -83,7 +83,6 @@ public static MutableExtensionRegistry createRegistryWithDefaultExtensions(Jupit
8383
DEFAULT_STATELESS_EXTENSIONS.forEach(extensionRegistry::registerDefaultExtension);
8484

8585
extensionRegistry.registerDefaultExtension(new TempDirectory(configuration));
86-
extensionRegistry.registerDefaultExtension(new DefaultTimeZoneExtension());
8786

8887
if (configuration.isExtensionAutoDetectionEnabled()) {
8988
registerAutoDetectedExtensions(extensionRegistry, configuration);
@@ -103,14 +102,14 @@ private static void registerAutoDetectedExtensions(MutableExtensionRegistry exte
103102
List<Class<? extends Extension>> excludedExtensions = new ArrayList<>();
104103

105104
ServiceLoader<Extension> serviceLoader = ServiceLoader.load(Extension.class,
106-
ClassLoaderUtils.getDefaultClassLoader());
105+
ClassLoaderUtils.getDefaultClassLoader());
107106
ServiceLoaderUtils.filter(serviceLoader, clazz -> {
108-
boolean included = filter.test(clazz);
109-
if (!included) {
110-
excludedExtensions.add(clazz);
111-
}
112-
return included;
113-
}) //
107+
boolean included = filter.test(clazz);
108+
if (!included) {
109+
excludedExtensions.add(clazz);
110+
}
111+
return included;
112+
}) //
114113
.forEach(extensionRegistry::registerAutoDetectedExtension);
115114

116115
logExcludedExtensions(excludedExtensions);
@@ -125,7 +124,7 @@ private static void logExcludedExtensions(List<Class<? extends Extension>> exclu
125124
.toList();
126125
// @formatter:on
127126
logger.config(() -> "Excluded auto-detected extensions due to configured includes/excludes: %s".formatted(
128-
excludeExtensionNames));
127+
excludeExtensionNames));
129128
}
130129
}
131130

@@ -218,7 +217,7 @@ public void registerUninitializedExtension(Class<?> testClass, Field source,
218217
Preconditions.notNull(initializer, "initializer must not be null");
219218

220219
logger.trace(() -> "Registering local extension (late-init) for [%s]%s".formatted(source.getType().getName(),
221-
buildSourceInfo(source)));
220+
buildSourceInfo(source)));
222221

223222
LateInitEntry entry = getLateInitExtensions(testClass) //
224223
.add(new LateInitEntry(testClass, initializer));
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* https://www.eclipse.org/legal/epl-v20.html
99
*/
1010

11-
package org.junit.jupiter.engine.extension;
11+
package org.junit.jupiter.api.util;
1212

1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.junit.jupiter.testkit.JUnitJupiterTestKit.executeTestClass;
@@ -27,9 +27,6 @@
2727
import org.junit.jupiter.api.Test;
2828
import org.junit.jupiter.api.TestInstance;
2929
import org.junit.jupiter.api.extension.ExtensionConfigurationException;
30-
import org.junit.jupiter.api.util.DefaultTimeZone;
31-
import org.junit.jupiter.api.util.ReadsDefaultTimeZone;
32-
import org.junit.jupiter.api.util.TimeZoneProvider;
3330
import org.junit.jupiter.testkit.ExecutionResults;
3431

3532
@DisplayName("DefaultTimeZone extension")
@@ -209,10 +206,10 @@ class ConfigurationTests {
209206
@DisplayName("on method level, throws exception")
210207
void throwsWhenConfigurationIsBad() {
211208
ExecutionResults results = executeTestMethod(BadMethodLevelConfigurationTestCases.class,
212-
"badConfiguration");
209+
"badConfiguration");
213210
results.testEvents().assertThatEvents().haveAtMost(1,
214-
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
215-
message(it -> it.contains("@DefaultTimeZone not configured correctly."))));
211+
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
212+
message(it -> it.contains("@DefaultTimeZone not configured correctly."))));
216213
}
217214

218215
@Test
@@ -222,8 +219,8 @@ void shouldThrowWithBadConfiguration() {
222219
ExecutionResults results = executeTestClass(BadClassLevelConfigurationTestCases.class);
223220

224221
results.testEvents().assertThatEvents().haveAtMost(1,
225-
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
226-
message(it -> it.contains("@DefaultTimeZone not configured correctly."))));
222+
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
223+
message(it -> it.contains("@DefaultTimeZone not configured correctly."))));
227224
}
228225

229226
@AfterEach
@@ -293,8 +290,8 @@ void throwsForMutuallyExclusiveOptions() {
293290
ExecutionResults results = executeTestMethod(BadTimeZoneProviderTestCases.class, "notExclusive");
294291

295292
results.testEvents().assertThatEvents().haveAtMost(1,
296-
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
297-
message(it -> it.contains("Either a valid time zone id or a TimeZoneProvider must be provided"))));
293+
finishedWithFailure(instanceOf(ExtensionConfigurationException.class), message(it -> it.contains(
294+
"Either a valid time zone id or a TimeZoneProvider must be provided"))));
298295
}
299296

300297
@Test
@@ -304,8 +301,8 @@ void throwsForEmptyOptions() {
304301
ExecutionResults results = executeTestMethod(BadTimeZoneProviderTestCases.class, "empty");
305302

306303
results.testEvents().assertThatEvents().haveAtMost(1,
307-
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
308-
message(it -> it.contains("Either a valid time zone id or a TimeZoneProvider must be provided"))));
304+
finishedWithFailure(instanceOf(ExtensionConfigurationException.class), message(it -> it.contains(
305+
"Either a valid time zone id or a TimeZoneProvider must be provided"))));
309306
}
310307

311308
@Test
@@ -315,8 +312,8 @@ void throwsForBadConstructor() {
315312
ExecutionResults results = executeTestMethod(BadTimeZoneProviderTestCases.class, "noConstructor");
316313

317314
results.testEvents().assertThatEvents().haveAtMost(1,
318-
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
319-
message(it -> it.contains("Could not instantiate TimeZoneProvider because of exception"))));
315+
finishedWithFailure(instanceOf(ExtensionConfigurationException.class),
316+
message(it -> it.contains("Could not instantiate TimeZoneProvider because of exception"))));
320317
}
321318

322319
}

0 commit comments

Comments
 (0)