KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > LanguageUtilTest


1 /*
2  * Filename: LanguageUtilTest.java
3  *
4  * Created on 13-Jul-04
5  */

6 package org.roller.presentation;
7
8 import java.util.Locale JavaDoc;
9 import java.util.Vector JavaDoc;
10
11 import javax.servlet.ServletContext JavaDoc;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.apache.log4j.BasicConfigurator;
16
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import com.mockrunner.mock.web.MockServletContext;
22
23 /**
24  * The purpose of this class is to
25  *
26  * @author <a HREF="mailto:molen@mail.com">Jaap van der Molen</a>
27  * @version $Revision: 1.1 $
28  */

29 public class LanguageUtilTest extends TestCase
30 {
31     private static Log logger = LogFactory.getLog(LanguageUtilTest.class);
32
33     private static String JavaDoc supportedLanguages = "en,nl,vi,zh_cn,zh_tw";
34
35     private ServletContext JavaDoc servletContext = null;
36
37     /**
38      * @param arg0
39      */

40     public LanguageUtilTest(String JavaDoc name)
41     {
42         super(name);
43         BasicConfigurator.configure();
44     }
45
46     /**
47      * @see junit.framework.TestCase#setUp()
48      */

49     protected void setUp() throws Exception JavaDoc
50     {
51         super.setUp();
52         servletContext = new MockServletContext();
53         servletContext.setAttribute(
54             LanguageUtil.SUPPORTED_LANGUAGES,
55             LanguageUtil.extractLanguages(supportedLanguages));
56     }
57
58     public static Test suite()
59     {
60         TestSuite suite = new TestSuite();
61         suite.addTest(new LanguageUtilTest("testSupportedLanguages"));
62         suite.addTest(new LanguageUtilTest("testIsSupported"));
63         return suite;
64     }
65     
66     public void testSupportedLanguages() {
67         Locale JavaDoc[] l = LanguageUtil.getSupportedLanguages(servletContext);
68
69         assertNotNull(l);
70
71         for (int i=0; i<l.length; i++) {
72             logger.debug("locale: "+l[i]);
73         }
74
75         assertEquals(l.length, 5);
76         assertEquals(l[0], new Locale JavaDoc("en"));
77         assertEquals(l[1], new Locale JavaDoc("nl"));
78         assertEquals(l[2], new Locale JavaDoc("vi"));
79         assertEquals(l[3], new Locale JavaDoc("zh", "cn"));
80         assertEquals(l[4], new Locale JavaDoc("zh", "tw"));
81         
82     }
83     
84     public void testIsSupported() {
85         assertTrue(LanguageUtil.isSupported( new Locale JavaDoc("en", "GB"), servletContext));
86         assertFalse(LanguageUtil.isSupported( new Locale JavaDoc("de"), servletContext));
87         assertTrue(LanguageUtil.isSupported( "en_GB", servletContext));
88         assertFalse(LanguageUtil.isSupported( "de", servletContext));
89     }
90
91 }
92
Popular Tags