-
@Retention(RUNTIME) @Target({METHOD,TYPE}) @Inherited @ExtendWith(DefaultLocaleExtension.class) public @interface DefaultLocale@DefaultLocaleis a JUnit Jupiter extension to change the value returned byLocale.getDefault()for a test execution.The
Localeto set as the default locale can be configured in several ways:- using a
language tag - using a
Locale.BuilderLocale.Builder} together with- a language
- a language and a county
- a language, a county, and a variant
Please keep in mind the the
Locale.Builderdoes a syntax check, if you use a variant! The given string must match the BCP 47 (or more detailed RFC 5646) syntax.If a language tag is set, none of the other fields must be set. Otherwise an
ExtensionConfigurationExceptionwill be thrown. Specifying acountry()but nolanguage(), or avariant()but nocountry()andlanguage()will also cause anExtensionConfigurationException. After the annotated element has been executed, the defaultLocalewill be restored to its original value.@DefaultLocalecan 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 configuredLocalewill be the defaultLocalefor all tests inside that class. Any method level configurations will override the class level defaultLocale.During parallel test execution, all tests annotated with
DefaultLocale,ReadsDefaultLocale, andWritesDefaultLocaleare scheduled in a way that guarantees correctness under mutation of shared global state.For more details and examples, see the documentation on
@DefaultLocaleand@DefaultTimeZone.- Since:
- 0.2
- See Also:
Locale.getDefault(),DefaultTimeZone
- using a
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringcountryAn ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code.java.lang.StringlanguageAn ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to 8 characters in length.java.lang.StringvalueA language tag string as specified by IETF BCP 47.java.lang.StringvariantAn IETF BCP 47 language string that matches the RFC 5646 syntax.
-
-
-
-
variant
java.lang.String variant
An IETF BCP 47 language string that matches the RFC 5646 syntax. It's validated by theLocale.Builder, usingsun.util.locale.LanguageTag#isVariant.- Default:
- ""
-
-