Restore initial locale at the end of a JUnit test case which modify it.

pull/144/head
luccioman 7 years ago
parent 7206f1ed71
commit d41ad7af6f

@ -44,11 +44,20 @@ public class TextParserTest {
*/
@Test
public void testSupportsMimeLocaleConsistency() {
for (Locale locale : Locale.getAvailableLocales()) {
Locale.setDefault(locale);
for (String mimeType : TextParser.supportedMimeTypes()) {
assertNull(locale + " " + mimeType, TextParser.supportsMime(mimeType.toUpperCase(Locale.ROOT)));
Locale initialDefaultLocale = Locale.getDefault();
try {
for (Locale locale : Locale.getAvailableLocales()) {
Locale.setDefault(locale);
for (String mimeType : TextParser.supportedMimeTypes()) {
assertNull(locale + " " + mimeType, TextParser.supportsMime(mimeType.toUpperCase(Locale.ROOT)));
}
}
} finally {
/*
* Restore the initial default locale to prevent side-effects on other JUnit
* tests run in the same session
*/
Locale.setDefault(initialDefaultLocale);
}
}

Loading…
Cancel
Save