Annotation Interface DefaultTimeZone


@Retention(RUNTIME) @Target({METHOD,TYPE}) @Inherited @API(status=STABLE, since="6.1") @ExtendWith(org.junit.jupiter.api.util.DefaultTimeZoneExtension.class) public @interface DefaultTimeZone
@DefaultTimeZone is a JUnit Jupiter extension for changing the value returned by TimeZone.getDefault() for a test execution.

The TimeZone to set as the default TimeZone is configured by specifying the TimeZone ID as defined by TimeZone.getTimeZone(String). After the annotated element has been executed, the default TimeZone will be restored to its original value.

@DefaultTimeZone can be used on the method and on the class level. It is inherited from higher-level containers, but can only be used once per method or class. If a class is annotated, the configured TimeZone will be the default TimeZone for all tests inside that class. Any method level configurations will override the class level default TimeZone.

During parallel test execution, all tests annotated with @DefaultTimeZone, @ReadsDefaultTimeZone, and @WritesDefaultTimeZone are scheduled in a way that guarantees correctness under mutation of shared global state.

For more details and examples, see the User Guide.

Since:
6.1
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    A class implementing TimeZoneProvider to be used for custom TimeZone resolution.
    The ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".
  • Element Details

    • value

      String value
      The ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
      Default:
      ""
    • timeZoneProvider

      Class<? extends TimeZoneProvider> timeZoneProvider
      A class implementing TimeZoneProvider to be used for custom TimeZone resolution. This is mutually exclusive with other properties, if any other property is given a value it will result in an ExtensionConfigurationException.
      Default:
      org.junit.jupiter.api.util.NullTimeZoneProvider.class