KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > common > LocaleInfoTestCase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.common;
10
11 import java.util.Iterator JavaDoc;
12 import java.util.Locale JavaDoc;
13
14 import junit.framework.TestCase;
15
16 import org.jboss.portal.common.util.LocaleInfo;
17
18 /**
19  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
20  * @version $Revision: 1.2 $
21  */

22 public class LocaleInfoTestCase extends TestCase
23 {
24    public LocaleInfoTestCase(String JavaDoc key)
25    {
26       super(key);
27    }
28
29    public void testParent()
30    {
31       // Locate a locale with language/country/variant to achieve the test
32
LocaleInfo info1 = null;
33       for (Iterator JavaDoc i = LocaleInfo.getAll().iterator();i.hasNext();)
34       {
35          LocaleInfo tmp = (LocaleInfo)i.next();
36          if (tmp.getLocale().getVariant() != null && tmp.getLocale().getVariant().length() > 0)
37          {
38             info1 = tmp;
39             break;
40          }
41       }
42
43       // The test to pass
44
assertNotNull("Cannot found a locale with language/country/variant", info1);
45
46       // Test the language/country parent
47
LocaleInfo info2 = info1.getParent();
48       assertNotNull(info2);
49       assertEquals(new Locale JavaDoc(info1.getLocale().getLanguage(), info1.getLocale().getCountry(), ""), info2.getLocale());
50
51       // Test the language parent
52
LocaleInfo info3 = info2.getParent();
53       assertNotNull(info3);
54       assertEquals(new Locale JavaDoc(info1.getLocale().getLanguage(), "", ""), info3.getLocale());
55
56       // Test no parent
57
LocaleInfo info4 = info3.getParent();
58       assertNull(info4);
59    }
60 }
61
Popular Tags