package skrueger.i8n; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; import schmitzm.junit.TestingClass; public class I8NUtilTest extends TestingClass { final static String oneLineCoded = "de{Baum}en{tree}"; final static List langs4 = new ArrayList(); @BeforeClass public static void setup() { langs4.add("de"); langs4.add("en"); langs4.add("xx"); langs4.add("yy"); } @Test public void testCreateFromOneLine() { Translation t = I8NUtil.createFromOneLine(oneLineCoded); assertEquals("Baum", t.toString("de")); assertEquals("tree", t.toString("en")); assertEquals(oneLineCoded, t.toOneLine()); } @Test public void testIsValidISOLangCode() { assertTrue(I8NUtil.isValidISOLangCode("de")); assertTrue(I8NUtil.isValidISOLangCode("ar")); assertFalse(I8NUtil.isValidISOLangCode("äü")); assertFalse(I8NUtil.isValidISOLangCode("ara")); } @Test public void testMitUmlaute() { assertEquals("öäü", I8NUtil.mitUmlaute("oeaeue")); } @Test public void testQmTranslation() { Translation t = I8NUtil.createFromOneLine(oneLineCoded); assertEquals(0.5, I8NUtil.qmTranslation(langs4, t), .00000000001); } @Test public void testGetLocalesForLang() { List locales = I8NUtil.getLocalesForLang("en"); assertTrue(locales.contains(new Locale("en", "za"))); assertTrue(locales.contains(new Locale("en", "sg"))); } @Test public void testGetLanguageCodes() { Set languageCodes = I8NUtil.getLanguageCodes(); assertTrue(languageCodes.contains("kj")); assertTrue(languageCodes.contains("od")); assertTrue(languageCodes.contains("ok")); } @Test public void testGetFirstLocaleForLang() { Locale tjLocaleSelfmade = I8NUtil.getFirstLocaleForLang("kj"); assertNotNull(tjLocaleSelfmade); System.out.println(tjLocaleSelfmade); } @Test public void testGetPropertiesLanguages() { Set propertiesLocales = I8NUtil.getPropertiesLanguages(); String o1 = propertiesLocales.iterator().next(); PropertiesLocale po1 = I8NUtil.propLocales.get(o1); assertTrue(po1.getDisplayCountry().startsWith("Namibi")); assertEquals("od", po1.getLanguage()); assertEquals("Oshindonga", po1.getDisplayLanguage()); assertEquals("Oshindonga", po1.getDisplayLanguage(Locale.GERMAN.getLanguage())); assertEquals("Oshindonga", po1.getDisplayLanguage(Locale.ENGLISH.getLanguage())); Translation t = new Translation(); t.put(po1.getLanguage(), "native"); t.put("en", "english"); Translation.setActiveLang("en"); assertEquals("english", t.toString()); Translation.setActiveLang(po1.getLanguage()); assertEquals("native", t.toString()); } }