use Languages class as source of locales to test

This commit is contained in:
Hans-Christoph Steiner 2017-04-18 21:35:54 +02:00
parent 3a194026fa
commit 67f40367cd
2 changed files with 6 additions and 5 deletions

View File

@ -14,9 +14,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -35,7 +34,7 @@ public class LocalizationTest {
private final Pattern androidFormat = Pattern.compile("(%[a-z0-9]\\$?[a-z]?)"); private final Pattern androidFormat = Pattern.compile("(%[a-z0-9]\\$?[a-z]?)");
private final Locale[] locales = Locale.getAvailableLocales(); private final Locale[] locales = Locale.getAvailableLocales();
private final ArrayList<String> localeNames = new ArrayList<>(locales.length); private final HashSet<String> localeNames = new HashSet<>(locales.length);
private AssetManager assets; private AssetManager assets;
private Configuration config; private Configuration config;
@ -43,10 +42,12 @@ public class LocalizationTest {
@Before @Before
public void setUp() { public void setUp() {
for (Locale locale : Languages.LOCALES_TO_TEST) {
localeNames.add(locale.toString());
}
for (Locale locale : locales) { for (Locale locale : locales) {
localeNames.add(locale.toString()); localeNames.add(locale.toString());
} }
Collections.sort(localeNames);
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
Context context = instrumentation.getTargetContext(); Context context = instrumentation.getTargetContext();

View File

@ -203,7 +203,7 @@ public final class Languages {
return Character.toUpperCase(line.charAt(0)) + line.substring(1); return Character.toUpperCase(line.charAt(0)) + line.substring(1);
} }
private static final Locale[] LOCALES_TO_TEST = { public static final Locale[] LOCALES_TO_TEST = {
Locale.ENGLISH, Locale.ENGLISH,
Locale.FRENCH, Locale.FRENCH,
Locale.GERMAN, Locale.GERMAN,