public final class JavaDefaultLocale extends org.junit.rules.ExternalResource
default locale to a
desired locale and resets it after the tests to the value before.
This is useful e.g. for tests which relies on SimpleDateFormat
because this piece of crap uses the systems locale in a non accessible static
way. Which leads to tests which works on OS with one local but not on
machines with an other locale. Praise the SUN engineers, not!
Example:
public class TestSomething {
@Rule
public final JavaDefaultLocale localeRule = new JavaDefaultLocale(Locale.ENGLISH);
@Test
public void someTestMethod() {}
}
| Modifier and Type | Field and Description |
|---|---|
private Locale |
backup
The origin locale.
|
private Locale |
wanted
The locale wanted as default for Java's locale.
|
| Constructor and Description |
|---|
JavaDefaultLocale(Locale wanted)
Dedicated constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
protected void |
before() |
applyprivate final Locale wanted
private Locale backup
public JavaDefaultLocale(Locale wanted)
wanted - must not be nullprotected void before()
throws Throwable
before in class org.junit.rules.ExternalResourceThrowableprotected void after()
after in class org.junit.rules.ExternalResourceCopyright © 2014 Sven Strittmatter. All Rights Reserved.