litesoft
@ 932
litesoft / trunk / DeviceDesktopTest / src / org / litesoft / locale / DerivedLocaleGraphTest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package org.litesoft.locale; import junit.framework.AssertionFailedError; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; public class DerivedLocaleGraphTest { private static final List<String> FRENCH_CANADIAN = toCodes(Locale.CANADA_FRENCH, Locale.FRENCH, Locale.CANADA, Locale.ENGLISH); private static final List<String> ENGLISH_CANADIAN = toCodes(Locale.CANADA, Locale.ENGLISH); private static final List<String> ENGLISH_US = toCodes(Locale.US, Locale.ENGLISH); private static final List<String> MEXICAN_US = toCodes(new Locale("es", "MX"), new Locale("es"), Locale.US, Locale.ENGLISH); private static final List<String> BRITAIN = toCodes(Locale.UK, Locale.ENGLISH); private static final List<String> GERMAN = toCodes(Locale.GERMANY, Locale.GERMAN); private static final List<String> FRANCE = toCodes(Locale.FRANCE, Locale.FRENCH); private static final List<String> TAIWAN = toCodes(Locale.TAIWAN, Locale.TRADITIONAL_CHINESE, Locale.CHINESE, Locale.SIMPLIFIED_CHINESE, Locale.ENGLISH); private static final List<String> CHINA = toCodes(Locale.CHINA, Locale.PRC, Locale.CHINESE, Locale.SIMPLIFIED_CHINESE); private static final List<String> JAPAN = toCodes(Locale.JAPAN, Locale.JAPANESE, Locale.ENGLISH); private static final List<String> KOREA = toCodes(Locale.KOREA, Locale.KOREAN); private static final List<String> ITALY = toCodes(Locale.ITALY, Locale.ITALIAN); @Test public void testSelect() throws Exception { expectSelected(Locale_en_US.INSTANCE, ENGLISH_US, Locale_en_US.INSTANCE); expectSelected(Locale_en_US.INSTANCE, ENGLISH_CANADIAN, Locale_en_US.INSTANCE, Locale_de_DE.INSTANCE); expectSelected(Locale_fr_FR.INSTANCE, FRENCH_CANADIAN, Locale_en_US.INSTANCE, Locale_de_DE.INSTANCE, Locale_fr_FR.INSTANCE); expectSelected(Locale_es_ES.INSTANCE, MEXICAN_US, Locale_en_US.INSTANCE, Locale_de_DE.INSTANCE, Locale_fr_FR.INSTANCE, Locale_es_ES.INSTANCE); } private void expectSelected(AbstractLocale pExpected, List<String> pLocaleCodesToTest, AbstractLocale... pSupported) { AbstractLocale zSelected = DerivedLocaleGraph.select(Locales.toSet(pSupported), pLocaleCodesToTest); if (!pExpected.equals(zSelected)) { throw new AssertionFailedError("" + "Expected: " + pExpected + "\n" + " Actual: " + zSelected + "\n" + "Supported: " + Arrays.asList(pSupported) + "\n" + "Acceptable: " + pLocaleCodesToTest ); } } private static List<String> toCodes(Locale... pLocales) { List<String> zCodes = new ArrayList<>(pLocales.length); for (Locale zLocale : pLocales) { zCodes.add(AbstractLocale.toCode(zLocale.getLanguage(), zLocale.getCountry())); } return Collections.unmodifiableList(zCodes); } } |