/[schmitzm]/trunk/src_junit/skrueger/i8n/I8NUtilTest.java
ViewVC logotype

Annotation of /trunk/src_junit/skrueger/i8n/I8NUtilTest.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1373 - (hide annotations)
Wed Jan 19 12:59:51 2011 UTC (14 years, 1 month ago) by alfonx
File MIME type: text/plain
File size: 2925 byte(s)
GP-Feature: Added support for "user defined Locales". This allows to define a language, that is only spoken in a small area and which is not a official ISO language.
1 alfonx 1097 package skrueger.i8n;
2    
3     import static org.junit.Assert.assertEquals;
4     import static org.junit.Assert.assertFalse;
5 alfonx 1150 import static org.junit.Assert.assertNotNull;
6 alfonx 1097 import static org.junit.Assert.assertTrue;
7    
8     import java.util.ArrayList;
9     import java.util.List;
10 alfonx 1100 import java.util.Locale;
11 alfonx 1150 import java.util.Set;
12 alfonx 1097
13     import org.junit.BeforeClass;
14     import org.junit.Test;
15    
16 alfonx 1332 import schmitzm.junit.TestingClass;
17 alfonx 1373
18 alfonx 1332 public class I8NUtilTest extends TestingClass {
19 alfonx 1097
20     final static String oneLineCoded = "de{Baum}en{tree}";
21     final static List<String> langs4 = new ArrayList<String>();
22    
23     @BeforeClass
24     public static void setup() {
25     langs4.add("de");
26     langs4.add("en");
27     langs4.add("xx");
28     langs4.add("yy");
29     }
30    
31     @Test
32     public void testCreateFromOneLine() {
33     Translation t = I8NUtil.createFromOneLine(oneLineCoded);
34     assertEquals("Baum", t.toString("de"));
35     assertEquals("tree", t.toString("en"));
36     assertEquals(oneLineCoded, t.toOneLine());
37     }
38    
39     @Test
40     public void testIsValidISOLangCode() {
41     assertTrue(I8NUtil.isValidISOLangCode("de"));
42     assertTrue(I8NUtil.isValidISOLangCode("ar"));
43     assertFalse(I8NUtil.isValidISOLangCode("äü"));
44     assertFalse(I8NUtil.isValidISOLangCode("ara"));
45     }
46    
47     @Test
48     public void testMitUmlaute() {
49     assertEquals("öäü", I8NUtil.mitUmlaute("oeaeue"));
50     }
51    
52     @Test
53     public void testQmTranslation() {
54     Translation t = I8NUtil.createFromOneLine(oneLineCoded);
55     assertEquals(0.5, I8NUtil.qmTranslation(langs4, t), .00000000001);
56     }
57    
58 alfonx 1100 @Test
59     public void testGetLocalesForLang() {
60     List<Locale> locales = I8NUtil.getLocalesForLang("en");
61    
62     assertTrue(locales.contains(new Locale("en", "za")));
63     assertTrue(locales.contains(new Locale("en", "sg")));
64     }
65    
66 alfonx 1150 @Test
67     public void testGetLanguageCodes() {
68     Set<String> languageCodes = I8NUtil.getLanguageCodes();
69    
70     assertTrue(languageCodes.contains("kj"));
71 alfonx 1373
72     assertTrue(languageCodes.contains("x1"));
73     assertTrue(languageCodes.contains("x2"));
74    
75 alfonx 1150 }
76    
77     @Test
78     public void testGetFirstLocaleForLang() {
79     Locale tjLocaleSelfmade = I8NUtil.getFirstLocaleForLang("kj");
80     assertNotNull(tjLocaleSelfmade);
81     System.out.println(tjLocaleSelfmade);
82     }
83 alfonx 1373
84     @Test
85     public void testGetPropertiesLanguages() {
86     Set<String> propertiesLocales = I8NUtil.getPropertiesLanguages();
87     String o1 = propertiesLocales.iterator().next();
88    
89     PropertiesLocale po1 = I8NUtil.propLocales.get(o1);
90    
91     assertEquals("Namibia", po1.getDisplayCountry());
92     assertEquals("x2", po1.getLanguage());
93     assertEquals("Oshindonga", po1.getDisplayLanguage());
94     assertEquals("Oshindonga",
95     po1.getDisplayLanguage(Locale.GERMAN.getLanguage()));
96     assertEquals("Oshindonga",
97     po1.getDisplayLanguage(Locale.ENGLISH.getLanguage()));
98    
99     Translation t = new Translation();
100     t.put(po1.getLanguage(), "native");
101     t.put("en", "english");
102    
103     Translation.setActiveLang("en");
104     assertEquals("english", t.toString());
105     Translation.setActiveLang(po1.getLanguage());
106     assertEquals("native", t.toString());
107     }
108 alfonx 1097 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26