1 6 package org.roller.presentation; 7 8 import java.util.Locale ; 9 import java.util.Vector ; 10 11 import javax.servlet.ServletContext ; 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 29 public class LanguageUtilTest extends TestCase 30 { 31 private static Log logger = LogFactory.getLog(LanguageUtilTest.class); 32 33 private static String supportedLanguages = "en,nl,vi,zh_cn,zh_tw"; 34 35 private ServletContext servletContext = null; 36 37 40 public LanguageUtilTest(String name) 41 { 42 super(name); 43 BasicConfigurator.configure(); 44 } 45 46 49 protected void setUp() throws Exception 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 [] 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 ("en")); 77 assertEquals(l[1], new Locale ("nl")); 78 assertEquals(l[2], new Locale ("vi")); 79 assertEquals(l[3], new Locale ("zh", "cn")); 80 assertEquals(l[4], new Locale ("zh", "tw")); 81 82 } 83 84 public void testIsSupported() { 85 assertTrue(LanguageUtil.isSupported( new Locale ("en", "GB"), servletContext)); 86 assertFalse(LanguageUtil.isSupported( new Locale ("de"), servletContext)); 87 assertTrue(LanguageUtil.isSupported( "en_GB", servletContext)); 88 assertFalse(LanguageUtil.isSupported( "de", servletContext)); 89 } 90 91 } 92 | Popular Tags |