Author: julien(a)jboss.com
Date: 2008-01-09 12:17:49 -0500 (Wed, 09 Jan 2008)
New Revision: 9467
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleClassLoader.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameParserTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ComplexResourceBundleFactoryTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/DescriptionTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocalizedStringTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ParentChildResourceBundleTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/SimpleResourceBundleTestCase.java
Removed:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameIteratorTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameParserTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ComplexResourceBundleFactoryTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/DescriptionTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocaleFormatTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocalizedStringTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParentChildResourceBundleTestCase.java
Modified:
modules/common/trunk/common/pom.xml
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/SimpleResourceBundleFactory.java
Log:
move i18n tests in their own package and fix the implementation of
SimpleResourceBundleFactory with now test cases
Modified: modules/common/trunk/common/pom.xml
===================================================================
--- modules/common/trunk/common/pom.xml 2008-01-09 16:17:51 UTC (rev 9466)
+++ modules/common/trunk/common/pom.xml 2008-01-09 17:17:49 UTC (rev 9467)
@@ -126,7 +126,7 @@
<argLine>-enableassertions</argLine>
-->
<excludes>
-
<exclude>org/jboss/portal/test/common/BundleNameParserTestCase*.java</exclude>
+
<exclude>org/jboss/portal/test/common/i18n/BundleNameParserTestCase*.java</exclude>
<exclude>org/jboss/portal/test/common/net/URLNavigatorTestCase.java</exclude>
</excludes>
</configuration>
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/SimpleResourceBundleFactory.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/SimpleResourceBundleFactory.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/SimpleResourceBundleFactory.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -24,6 +24,7 @@
import java.util.Locale;
import java.util.ResourceBundle;
+import java.util.MissingResourceException;
/**
* An implementation that delegates bundle loading to
<code>ResourceBundle.getBundle(String,Locale,ClassLoader)</code>.
@@ -40,6 +41,12 @@
/** The classloader to load resource from. */
private ClassLoader classLoader;
+ /**
+ *
+ * @param baseName the base name for loading
+ * @param classLoader the classloader for loading
+ * @throws IllegalArgumentException if any argument is null
+ */
public SimpleResourceBundleFactory(String baseName, ClassLoader classLoader) throws
IllegalArgumentException
{
if (baseName == null)
@@ -56,6 +63,17 @@
public ResourceBundle getBundle(Locale locale) throws IllegalArgumentException
{
- return ResourceBundle.getBundle(baseName, locale, classLoader);
+ if (locale == null)
+ {
+ throw new IllegalArgumentException("No null locale accepted");
+ }
+ try
+ {
+ return ResourceBundle.getBundle(baseName, locale, classLoader);
+ }
+ catch (MissingResourceException e)
+ {
+ return null;
+ }
}
}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameIteratorTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameIteratorTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameIteratorTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,206 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-
-import java.util.Locale;
-import java.util.NoSuchElementException;
-
-import org.jboss.portal.common.i18n.BundleName;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class BundleNameIteratorTestCase extends TestCase
-{
-
- private final String A = new Locale("a", "b",
"c").getLanguage();
- private final String B = new Locale("a", "b",
"c").getCountry();
- private final String C = new Locale("a", "b",
"c").getVariant();
-
- public void testNameLookup1()
- {
- Locale l = new Locale("a", "b", "c");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B + "_" + C,
iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup2()
- {
- Locale l = new Locale("a", "b");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup4()
- {
- Locale l = new Locale("a", "b", "");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup3()
- {
- Locale l = new Locale("a");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup5()
- {
- Locale l = new Locale("a", "", "");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup6()
- {
- Locale l = new Locale("a", "", "c");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "__" + C, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup7()
- {
- Locale l = new Locale("", "b", "c");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base__" + B + "_" + C, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base__" + B, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-
- public void testNameLookup8()
- {
- Locale l = new Locale("", "", "c");
- BundleName.Iterator iterator = new BundleName.Iterator("base", l);
- assertTrue(iterator.hasNext());
- assertEquals("base___" + C, iterator.next());
- assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
- assertFalse(iterator.hasNext());
- try
- {
- iterator.next();
- fail("Was expecting NoSuchElementException");
- }
- catch (NoSuchElementException expected)
- {
- }
- }
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameParserTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameParserTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/BundleNameParserTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,102 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-import org.jboss.portal.common.i18n.BundleName;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class BundleNameParserTestCase extends TestCase
-{
-
- /** . */
- private final BundleName.Parser parser = new BundleName.Parser();
-
-
- private static final Test[] tests = {
- new Test("_", null),
- new Test("__", null),
- new Test("___", null),
-
- //
- new Test("a", new BundleName("a")),
- new Test("a_b", new BundleName("a", "b")),
- new Test("a_b_c", new BundleName("a", "b",
"c")),
- new Test("a__b", new BundleName("a", "",
"b")),
- new Test("a___b", new BundleName("a", "",
"", "b")),
- new Test("a__b_c", new BundleName("a", "",
"b", "c")),
- new Test("a_b__c", new BundleName("a", "b",
"", "c")),
- new Test("a_b_c_d", new BundleName("a", "b",
"c", "d")),
-
- //
- new Test("", new BundleName("")),
- new Test("_b", new BundleName("", "b")),
- new Test("_b_c", new BundleName("", "b",
"c")),
- new Test("__b", new BundleName("", "",
"b")),
- new Test("___b", new BundleName("", "", "",
"b")),
- new Test("__b_c", new BundleName("", "",
"b", "c")),
- new Test("_b__c", new BundleName("", "b",
"", "c")),
- new Test("_b_c_d", new BundleName("", "b",
"c", "d")),
- };
-
- public void testA()
- {
- for (int i = 0; i < tests.length; i++)
- {
- Test test = tests[i];
- BundleName name = parser.parse(test.input, 0, test.input.length());
- if (name == null)
- {
- assertNull(test.input, test.expectedName);
- }
- else
- {
- assertNotNull(test.input, test.expectedName);
- assertEquals(test.input, test.expectedName.getBaseName(),
name.getBaseName());
- assertEquals(test.input, test.expectedName.getLanguage(),
name.getLanguage());
- assertEquals(test.input, test.expectedName.getCountry(), name.getCountry());
- assertEquals(test.input, test.expectedName.getVariant(), name.getVariant());
- }
- }
- }
-
-
- private static class Test
- {
-
- /** . */
- private String input;
-
- /** . */
- private BundleName expectedName;
-
- public Test(String input, BundleName expectedName)
- {
- this.input = input;
- this.expectedName = expectedName;
- }
- }
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ComplexResourceBundleFactoryTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ComplexResourceBundleFactoryTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ComplexResourceBundleFactoryTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,303 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.net.URLClassLoader;
-import java.net.URL;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-import org.jboss.portal.common.i18n.ComplexResourceBundleFactory;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ComplexResourceBundleFactoryTestCase extends TestCase
-{
-
- /** . */
- private ClassLoader cl;
-
- protected void setUp() throws Exception
- {
- URL bundleURL =
Thread.currentThread().getContextClassLoader().getResource("bundle");
- assertNotNull(bundleURL);
- File f = new File(bundleURL.getFile());
- assertTrue(f.exists());
- assertTrue(f.isDirectory());
- cl = new URLClassLoader(new URL[]{f.toURL()}, ClassLoader.getSystemClassLoader());
- }
-
- public void testExactMatch() throws Exception
- {
- Locale.setDefault(new Locale("ja"));
-
- //
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"a");
-
- //
- ResourceBundle a_de_DE = factory.getBundle(new Locale("de",
"DE"));
- assertNotNull(a_de_DE);
- assertEquals("a_de_DE", a_de_DE.getString("value"));
-
- //
- ResourceBundle a_fr = factory.getBundle(new Locale("fr"));
- assertNotNull(a_fr);
- assertEquals("a_fr", a_fr.getString("value"));
-
- //
- ResourceBundle a_fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(a_fr_FR);
- assertEquals("a_fr_FR", a_fr_FR.getString("value"));
-
- //
- ResourceBundle a_it = factory.getBundle(new Locale("it"));
- assertNotNull(a_it);
- assertEquals("a_it", a_it.getString("value"));
- }
-
- public void testNoMatch() throws Exception
- {
- Locale.setDefault(new Locale("ja"));
-
- //
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"a");
-
- //
- ResourceBundle a_de = factory.getBundle(new Locale("de"));
- assertNull(a_de);
-
- //
- ResourceBundle a_en = factory.getBundle(new Locale("en"));
- assertNull(a_en);
-
- //
- ResourceBundle a_en_EN = factory.getBundle(new Locale("en",
"EN"));
- assertNull(a_en_EN);
- }
-
- public void testFallbackOnDefaultLocale1() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"b");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("b", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("b", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("b", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("b", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("b", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("b", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale2() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"c");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("c_fr", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("c_fr", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("c_fr", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("c_fr", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("c_fr", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("c_fr", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale3() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"d");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNull(de);
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNull(fr);
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("d_fr_FR", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("d_fr_FR", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("d_fr_FR", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("d_fr_FR", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale4() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"e");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("e_fr", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("e_fr", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("e_fr", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("e_fr", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("e_fr", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("e_fr", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale5() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"f");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("f", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("f", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("f_fr_FR", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("f_fr_FR", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("f_fr_FR", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("f_fr_FR", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale6() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"g");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("g_fr", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("g_fr", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("g_fr_FR", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("g_fr_FR", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("g_fr", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("g_fr_FR", fr_FR.getString("value"));
- }
-
- public void testFallbackOnDefaultLocale7() throws Exception
- {
- ComplexResourceBundleFactory factory = new ComplexResourceBundleFactory(cl,
"h");
-
- //
- Locale.setDefault(new Locale("fr"));
- ResourceBundle de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("h_fr", de.getString("value"));
- ResourceBundle fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("h_fr", fr.getString("value"));
- ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
- assertNotNull(fr_FR);
- assertEquals("h_fr_FR", fr_FR.getString("value"));
-
- //
- Locale.setDefault(new Locale("fr", "FR"));
- de = factory.getBundle(new Locale("de"));
- assertNotNull(de);
- assertEquals("h_fr_FR", de.getString("value"));
- fr = factory.getBundle(new Locale("fr"));
- assertNotNull(fr);
- assertEquals("h_fr", fr.getString("value"));
- fr_FR = factory.getBundle(new Locale("fr", "FR"));
- assertNotNull(fr_FR);
- assertEquals("h_fr_FR", fr_FR.getString("value"));
- }
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/DescriptionTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/DescriptionTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/DescriptionTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,105 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Locale;
-
-import org.jboss.portal.common.i18n.LocalizedString;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6818 $
- */
-public class DescriptionTestCase extends TestCase
-{
-
- public DescriptionTestCase(String name)
- {
- super(name);
- }
-
- private Locale deflt = Locale.ENGLISH;
- private Locale abc = new Locale("a", "b", "c");
- private Locale ab = new Locale("a", "b");
- private Locale a = new Locale("a");
-
- public void testA()
- {
- Map map = new HashMap();
- map.put(abc, "abc");
- map.put(ab, "ab");
- map.put(a, "a");
- map.put(deflt, "deflt");
- LocalizedString desc = new LocalizedString(map, deflt);
- assertEquals("abc", desc.getString(abc, true));
- assertEquals("ab", desc.getString(ab, true));
- assertEquals("a", desc.getString(a, true));
- }
-
- public void testB()
- {
- Map map = new HashMap();
- map.put(abc, "abc");
- map.put(deflt, "deflt");
- LocalizedString desc = new LocalizedString(map, deflt);
- assertEquals("abc", desc.getString(abc, true));
- assertEquals("deflt", desc.getString(ab, true));
- assertEquals("deflt", desc.getString(a, true));
- }
-
- public void testC()
- {
- Map map = new HashMap();
- map.put(ab, "ab");
- map.put(deflt, "deflt");
- LocalizedString desc = new LocalizedString(map, deflt);
- assertEquals("ab", desc.getString(abc, true));
- assertEquals("ab", desc.getString(ab, true));
- assertEquals("deflt", desc.getString(a, true));
- }
-
- public void testD()
- {
- Map map = new HashMap();
- map.put(a, "a");
- map.put(deflt, "deflt");
- LocalizedString desc = new LocalizedString(map, deflt);
- assertEquals("a", desc.getString(abc, true));
- assertEquals("a", desc.getString(ab, true));
- assertEquals("a", desc.getString(a, true));
- }
-
- public void testE()
- {
- Map map = new HashMap();
- map.put(deflt, "deflt");
- LocalizedString desc = new LocalizedString(map, deflt);
- assertEquals("deflt", desc.getString(abc, true));
- assertEquals("deflt", desc.getString(ab, true));
- assertEquals("deflt", desc.getString(a, true));
- }
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocaleFormatTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocaleFormatTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocaleFormatTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,217 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-
-import java.util.Locale;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.Writer;
-import java.io.IOException;
-
-import org.jboss.portal.common.i18n.LocaleFormat;
-import org.jboss.portal.common.i18n.CachingLocaleFormat;
-import org.jboss.portal.common.i18n.AbstractLocaleFormat;
-import org.jboss.portal.common.util.FormatConversionException;
-import org.jboss.portal.common.util.ConversionException;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class LocaleFormatTestCase extends TestCase
-{
-
- public void testgetLocaleFromDefaultFormat() throws ConversionException
- {
- assertEquals(new Locale("a"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a"));
- assertEquals(new Locale("a", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b"));
- assertEquals(new Locale("", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("_b"));
- assertEquals(new Locale("a", "b", "c"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b_c"));
- assertEquals(new Locale("a", "", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a__b"));
- assertEquals(new Locale("", "a", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("_a_b"));
- assertEquals(new Locale(""),
LocaleFormat.DEFAULT_NO_CACHE.getLocale(""));
-
- //
- try
- {
- assertEquals(new Locale("", "", "a"),
LocaleFormat.DEFAULT.getLocale("__a"));
- fail();
- }
- catch (ConversionException expected)
- {
- }
- try
- {
- assertEquals(new Locale("", "", ""),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("__"));
- fail();
- }
- catch (ConversionException expected)
- {
- }
- try
- {
- LocaleFormat.DEFAULT.getLocale("_");
- fail();
- }
- catch (ConversionException expected)
- {
- }
- }
-
- public void testToStringFromDefaultFormat() throws ConversionException
- {
- assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a")));
- assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("")));
-
- //
- assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "")));
- assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b")));
- assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "")));
- assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a")));
-
- //
- assertEquals("a_B_c", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b", "c")));
- assertEquals("_A_b", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a", "b")));
- assertEquals("a__b", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "", "b")));
- assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b", "")));
- assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "", "a")));
- assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "", "")));
- assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a", "")));
- assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "", "")));
- }
-
- public void testGetLocaleFromRFC3066LanguageTag() throws ConversionException
- {
- assertEquals(new Locale("en"),
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en"));
- assertEquals(new Locale("en", "US"),
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en-US"));
-
- try
- {
- LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("wrong");
- fail("Should have failed since an invalid String was passed.");
- }
- catch (FormatConversionException e)
- {
- //expected
- }
-
- try
- {
- LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("zz");
- fail("Should have failed since an invalid language code was
passed.");
- }
- catch (FormatConversionException e)
- {
- //expected
- }
-
- try
- {
- LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("fr-ZZ");
- fail("Should have failed since an invalid country code was passed.");
- }
- catch (FormatConversionException e)
- {
- //expected
- }
-
- // weird combination should work as well
- LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("fr-US");
- }
-
- public void testGetRFC3066LanguageTagFromLocale() throws ConversionException
- {
- assertEquals("en",
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en")));
- assertEquals("en-US",
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en",
"US")));
- }
-
- public void testCachingLocaleFormat() throws ConversionException
- {
- TestLocaleFormat delegate = new TestLocaleFormat();
- delegate.put(new Locale("abc"), "abc");
- CachingLocaleFormat format = new CachingLocaleFormat(delegate);
-
- //
- assertEquals(new Locale("abc"), format.getLocale("abc"));
- assertEquals("abc", format.toString(new Locale("abc")));
-
- //
- try
- {
- format.getLocale("def");
- fail();
- }
- catch (ConversionException e)
- {
- }
-
- //
- try
- {
- format.toString(new Locale("def"));
- fail();
- }
- catch (ConversionException e)
- {
- }
- }
-
- private static class TestLocaleFormat extends AbstractLocaleFormat
- {
-
- /** . */
- private final Map localeToString = new HashMap();
-
- /** . */
- private final Map stringToLocale = new HashMap();
-
- private void put(Locale locale, String string)
- {
- localeToString.put(locale, string);
- stringToLocale.put(string, locale);
- }
-
- protected Locale internalGetLocale(String value) throws ConversionException
- {
- Locale locale = (Locale)stringToLocale.get(value);
- if (locale == null)
- {
- throw new ConversionException();
- }
- return locale;
- }
-
- protected void internalWrite(Locale locale, Writer writer) throws IOException,
ConversionException
- {
- String string = (String)localeToString.get(locale);
- if (string == null)
- {
- throw new ConversionException();
- }
- writer.write(string);
- }
- }
-
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocalizedStringTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocalizedStringTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/LocalizedStringTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,89 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-import org.jboss.portal.common.i18n.LocalizedString;
-
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 6818 $
- */
-public class LocalizedStringTestCase extends TestCase
-{
- private Map<Locale, String> values = new HashMap<Locale, String>();
- private LocalizedString localizedString;
-
- protected void setUp() throws Exception
- {
- values.put(Locale.ENGLISH, "labour");
- values.put(Locale.FRENCH, "travail");
- values.put(Locale.US, "labor");
- localizedString = new LocalizedString(values, Locale.US);
- }
-
- public void testLocalizedStringValuesAreNotModifiable()
- {
- try
- {
- localizedString.getValues().clear();
- }
- catch (Exception expected)
- {
- assertTrue(localizedString.hasValues());
- }
- }
-
- public void testPreferredOrBestLocalizedMappingFor()
- {
- try
- {
- localizedString.getPreferredOrBestLocalizedMappingFor(null);
- fail("LocalizedString get most appropriate value for should have thrown an
IllegalArgumentException with a null argument");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // no desired locales: should return default
- checkValueAndLocale(Locale.US, new String[]{});
-
- checkValueAndLocale(Locale.ENGLISH, new String[]{"en", "en-US",
"aa"});
- checkValueAndLocale(Locale.US, new String[]{"en-US", "en",
"aa"});
- checkValueAndLocale(Locale.FRENCH, new String[]{"fr-CA"});
- }
-
- private void checkValueAndLocale(Locale locale, String[] desiredLocales)
- {
- LocalizedString.Value mapping =
localizedString.getPreferredOrBestLocalizedMappingFor(desiredLocales);
-
- Locale foundLocale = mapping.getLocale();
- assertEquals(locale, foundLocale);
- assertEquals(values.get(foundLocale), mapping.getString());
- assertEquals(mapping.getString(),
localizedString.getMostAppropriateValueFor(desiredLocales));
- }
-}
Deleted:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParentChildResourceBundleTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParentChildResourceBundleTestCase.java 2008-01-09
16:17:51 UTC (rev 9466)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParentChildResourceBundleTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -1,115 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Vector;
-
-import junit.framework.TestCase;
-
-import org.jboss.portal.common.i18n.ParentChildResourceBundle;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6818 $
- */
-public class ParentChildResourceBundleTestCase extends TestCase
-{
- public ParentChildResourceBundleTestCase(String name)
- {
- super(name);
- }
-
- public void testBasic()
- {
- ResourceBundle parent = new ResourceBundle()
- {
- protected Object handleGetObject(String key)
- {
- if ("key-a".equals(key))
- {
- return "parent-a";
- }
- if ("key-b".equals(key))
- {
- return "parent-b";
- }
- return null;
- }
- public Enumeration getKeys()
- {
- Vector keys = new Vector();
- keys.add("key-a");
- keys.add("key-b");
- return keys.elements();
- }
- public Locale getLocale()
- {
- return Locale.CHINA;
- }
- };
- ResourceBundle child = new ResourceBundle()
- {
- protected Object handleGetObject(String key)
- {
- if ("key-a".equals(key))
- {
- return "child-a";
- }
- if ("key-c".equals(key))
- {
- return "child-c";
- }
- return null;
- }
- public Enumeration getKeys()
- {
- Vector keys = new Vector();
- keys.add("key-a");
- keys.add("key-c");
- return keys.elements();
- }
- public Locale getLocale()
- {
- return Locale.GERMAN;
- }
- };
- ResourceBundle bundle = new ParentChildResourceBundle(parent, child);
- assertEquals(Locale.GERMAN, bundle.getLocale());
- assertEquals("child-a", bundle.getString("key-a"));
- assertEquals("parent-b", bundle.getString("key-b"));
- assertEquals("child-c", bundle.getString("key-c"));
- Set keys = new HashSet(Arrays.asList(new
Object[]{"key-a","key-b","key-c"}));
- for (Enumeration e = bundle.getKeys();e.hasMoreElements();)
- {
- assertTrue(keys.remove(e.nextElement()));
- }
- assertTrue(keys.isEmpty());
- }
-
-}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleClassLoader.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleClassLoader.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleClassLoader.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.Assert;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.MalformedURLException;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class BundleClassLoader
+{
+
+ private static ClassLoader instance;
+
+ public synchronized static ClassLoader assertExists()
+ {
+ if (instance == null)
+ {
+ URL bundleURL =
Thread.currentThread().getContextClassLoader().getResource("bundle");
+ Assert.assertNotNull(bundleURL);
+ File f = new File(bundleURL.getFile());
+ Assert.assertTrue(f.exists());
+ Assert.assertTrue(f.isDirectory());
+
+ //
+ try
+ {
+ URL url = f.toURL();
+ instance = new URLClassLoader(new URL[]{url},
ClassLoader.getSystemClassLoader());
+ }
+ catch (MalformedURLException e)
+ {
+ Assert.fail("Cannot get URL value " + e.getMessage());
+ }
+ }
+
+ //
+ return instance;
+ }
+
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,206 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.util.NoSuchElementException;
+
+import org.jboss.portal.common.i18n.BundleName;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleNameIteratorTestCase extends TestCase
+{
+
+ private final String A = new Locale("a", "b",
"c").getLanguage();
+ private final String B = new Locale("a", "b",
"c").getCountry();
+ private final String C = new Locale("a", "b",
"c").getVariant();
+
+ public void testNameLookup1()
+ {
+ Locale l = new Locale("a", "b", "c");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A + "_" + B + "_" + C,
iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A + "_" + B, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup2()
+ {
+ Locale l = new Locale("a", "b");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A + "_" + B, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup4()
+ {
+ Locale l = new Locale("a", "b", "");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A + "_" + B, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup3()
+ {
+ Locale l = new Locale("a");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup5()
+ {
+ Locale l = new Locale("a", "", "");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup6()
+ {
+ Locale l = new Locale("a", "", "c");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A + "__" + C, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base_" + A, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup7()
+ {
+ Locale l = new Locale("", "b", "c");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base__" + B + "_" + C, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base__" + B, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+
+ public void testNameLookup8()
+ {
+ Locale l = new Locale("", "", "c");
+ BundleName.Iterator iterator = new BundleName.Iterator("base", l);
+ assertTrue(iterator.hasNext());
+ assertEquals("base___" + C, iterator.next());
+ assertTrue(iterator.hasNext());
+ assertEquals("base", iterator.next());
+ assertFalse(iterator.hasNext());
+ try
+ {
+ iterator.next();
+ fail("Was expecting NoSuchElementException");
+ }
+ catch (NoSuchElementException expected)
+ {
+ }
+ }
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameParserTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameParserTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameParserTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,102 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.i18n.BundleName;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleNameParserTestCase extends TestCase
+{
+
+ /** . */
+ private final BundleName.Parser parser = new BundleName.Parser();
+
+
+ private static final Test[] tests = {
+ new Test("_", null),
+ new Test("__", null),
+ new Test("___", null),
+
+ //
+ new Test("a", new BundleName("a")),
+ new Test("a_b", new BundleName("a", "b")),
+ new Test("a_b_c", new BundleName("a", "b",
"c")),
+ new Test("a__b", new BundleName("a", "",
"b")),
+ new Test("a___b", new BundleName("a", "",
"", "b")),
+ new Test("a__b_c", new BundleName("a", "",
"b", "c")),
+ new Test("a_b__c", new BundleName("a", "b",
"", "c")),
+ new Test("a_b_c_d", new BundleName("a", "b",
"c", "d")),
+
+ //
+ new Test("", new BundleName("")),
+ new Test("_b", new BundleName("", "b")),
+ new Test("_b_c", new BundleName("", "b",
"c")),
+ new Test("__b", new BundleName("", "",
"b")),
+ new Test("___b", new BundleName("", "", "",
"b")),
+ new Test("__b_c", new BundleName("", "",
"b", "c")),
+ new Test("_b__c", new BundleName("", "b",
"", "c")),
+ new Test("_b_c_d", new BundleName("", "b",
"c", "d")),
+ };
+
+ public void testA()
+ {
+ for (int i = 0; i < tests.length; i++)
+ {
+ Test test = tests[i];
+ BundleName name = parser.parse(test.input, 0, test.input.length());
+ if (name == null)
+ {
+ assertNull(test.input, test.expectedName);
+ }
+ else
+ {
+ assertNotNull(test.input, test.expectedName);
+ assertEquals(test.input, test.expectedName.getBaseName(),
name.getBaseName());
+ assertEquals(test.input, test.expectedName.getLanguage(),
name.getLanguage());
+ assertEquals(test.input, test.expectedName.getCountry(), name.getCountry());
+ assertEquals(test.input, test.expectedName.getVariant(), name.getVariant());
+ }
+ }
+ }
+
+
+ private static class Test
+ {
+
+ /** . */
+ private String input;
+
+ /** . */
+ private BundleName expectedName;
+
+ public Test(String input, BundleName expectedName)
+ {
+ this.input = input;
+ this.expectedName = expectedName;
+ }
+ }
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ComplexResourceBundleFactoryTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ComplexResourceBundleFactoryTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ComplexResourceBundleFactoryTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,287 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.jboss.portal.common.i18n.ComplexResourceBundleFactory;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ComplexResourceBundleFactoryTestCase extends TestCase
+{
+
+ public void testExactMatch() throws Exception
+ {
+ Locale.setDefault(new Locale("ja"));
+
+ //
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "a");
+
+ //
+ ResourceBundle a_de_DE = factory.getBundle(new Locale("de",
"DE"));
+ assertNotNull(a_de_DE);
+ assertEquals("a_de_DE", a_de_DE.getString("value"));
+
+ //
+ ResourceBundle a_fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(a_fr);
+ assertEquals("a_fr", a_fr.getString("value"));
+
+ //
+ ResourceBundle a_fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(a_fr_FR);
+ assertEquals("a_fr_FR", a_fr_FR.getString("value"));
+
+ //
+ ResourceBundle a_it = factory.getBundle(new Locale("it"));
+ assertNotNull(a_it);
+ assertEquals("a_it", a_it.getString("value"));
+ }
+
+ public void testNoMatch() throws Exception
+ {
+ Locale.setDefault(new Locale("ja"));
+
+ //
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "a");
+
+ //
+ ResourceBundle a_de = factory.getBundle(new Locale("de"));
+ assertNull(a_de);
+
+ //
+ ResourceBundle a_en = factory.getBundle(new Locale("en"));
+ assertNull(a_en);
+
+ //
+ ResourceBundle a_en_EN = factory.getBundle(new Locale("en",
"EN"));
+ assertNull(a_en_EN);
+ }
+
+ public void testFallbackOnDefaultLocale1() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "b");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("b", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("b", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("b", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("b", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("b", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("b", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale2() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "c");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("c_fr", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("c_fr", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("c_fr", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("c_fr", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("c_fr", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("c_fr", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale3() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "d");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNull(de);
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNull(fr);
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("d_fr_FR", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("d_fr_FR", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("d_fr_FR", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("d_fr_FR", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale4() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "e");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("e_fr", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("e_fr", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("e_fr", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("e_fr", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("e_fr", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("e_fr", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale5() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "f");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("f", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("f", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("f_fr_FR", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("f_fr_FR", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("f_fr_FR", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("f_fr_FR", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale6() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "g");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("g_fr", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("g_fr", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("g_fr_FR", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("g_fr_FR", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("g_fr", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("g_fr_FR", fr_FR.getString("value"));
+ }
+
+ public void testFallbackOnDefaultLocale7() throws Exception
+ {
+ ComplexResourceBundleFactory factory = new
ComplexResourceBundleFactory(BundleClassLoader.assertExists(), "h");
+
+ //
+ Locale.setDefault(new Locale("fr"));
+ ResourceBundle de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("h_fr", de.getString("value"));
+ ResourceBundle fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("h_fr", fr.getString("value"));
+ ResourceBundle fr_FR = factory.getBundle(new Locale("fr",
"FR"));
+ assertNotNull(fr_FR);
+ assertEquals("h_fr_FR", fr_FR.getString("value"));
+
+ //
+ Locale.setDefault(new Locale("fr", "FR"));
+ de = factory.getBundle(new Locale("de"));
+ assertNotNull(de);
+ assertEquals("h_fr_FR", de.getString("value"));
+ fr = factory.getBundle(new Locale("fr"));
+ assertNotNull(fr);
+ assertEquals("h_fr", fr.getString("value"));
+ fr_FR = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(fr_FR);
+ assertEquals("h_fr_FR", fr_FR.getString("value"));
+ }
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/DescriptionTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/DescriptionTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/DescriptionTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6818 $
+ */
+public class DescriptionTestCase extends TestCase
+{
+
+ public DescriptionTestCase(String name)
+ {
+ super(name);
+ }
+
+ private Locale deflt = Locale.ENGLISH;
+ private Locale abc = new Locale("a", "b", "c");
+ private Locale ab = new Locale("a", "b");
+ private Locale a = new Locale("a");
+
+ public void testA()
+ {
+ Map map = new HashMap();
+ map.put(abc, "abc");
+ map.put(ab, "ab");
+ map.put(a, "a");
+ map.put(deflt, "deflt");
+ LocalizedString desc = new LocalizedString(map, deflt);
+ assertEquals("abc", desc.getString(abc, true));
+ assertEquals("ab", desc.getString(ab, true));
+ assertEquals("a", desc.getString(a, true));
+ }
+
+ public void testB()
+ {
+ Map map = new HashMap();
+ map.put(abc, "abc");
+ map.put(deflt, "deflt");
+ LocalizedString desc = new LocalizedString(map, deflt);
+ assertEquals("abc", desc.getString(abc, true));
+ assertEquals("deflt", desc.getString(ab, true));
+ assertEquals("deflt", desc.getString(a, true));
+ }
+
+ public void testC()
+ {
+ Map map = new HashMap();
+ map.put(ab, "ab");
+ map.put(deflt, "deflt");
+ LocalizedString desc = new LocalizedString(map, deflt);
+ assertEquals("ab", desc.getString(abc, true));
+ assertEquals("ab", desc.getString(ab, true));
+ assertEquals("deflt", desc.getString(a, true));
+ }
+
+ public void testD()
+ {
+ Map map = new HashMap();
+ map.put(a, "a");
+ map.put(deflt, "deflt");
+ LocalizedString desc = new LocalizedString(map, deflt);
+ assertEquals("a", desc.getString(abc, true));
+ assertEquals("a", desc.getString(ab, true));
+ assertEquals("a", desc.getString(a, true));
+ }
+
+ public void testE()
+ {
+ Map map = new HashMap();
+ map.put(deflt, "deflt");
+ LocalizedString desc = new LocalizedString(map, deflt);
+ assertEquals("deflt", desc.getString(abc, true));
+ assertEquals("deflt", desc.getString(ab, true));
+ assertEquals("deflt", desc.getString(a, true));
+ }
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,217 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.Writer;
+import java.io.IOException;
+
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.i18n.CachingLocaleFormat;
+import org.jboss.portal.common.i18n.AbstractLocaleFormat;
+import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.util.ConversionException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocaleFormatTestCase extends TestCase
+{
+
+ public void testgetLocaleFromDefaultFormat() throws ConversionException
+ {
+ assertEquals(new Locale("a"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a"));
+ assertEquals(new Locale("a", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b"));
+ assertEquals(new Locale("", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("_b"));
+ assertEquals(new Locale("a", "b", "c"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b_c"));
+ assertEquals(new Locale("a", "", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("a__b"));
+ assertEquals(new Locale("", "a", "b"),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("_a_b"));
+ assertEquals(new Locale(""),
LocaleFormat.DEFAULT_NO_CACHE.getLocale(""));
+
+ //
+ try
+ {
+ assertEquals(new Locale("", "", "a"),
LocaleFormat.DEFAULT.getLocale("__a"));
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ try
+ {
+ assertEquals(new Locale("", "", ""),
LocaleFormat.DEFAULT_NO_CACHE.getLocale("__"));
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ try
+ {
+ LocaleFormat.DEFAULT.getLocale("_");
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ }
+
+ public void testToStringFromDefaultFormat() throws ConversionException
+ {
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("")));
+
+ //
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "")));
+ assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b")));
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "")));
+ assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a")));
+
+ //
+ assertEquals("a_B_c", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b", "c")));
+ assertEquals("_A_b", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a", "b")));
+ assertEquals("a__b", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "", "b")));
+ assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "b", "")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "", "a")));
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("a", "", "")));
+ assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "a", "")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new
Locale("", "", "")));
+ }
+
+ public void testGetLocaleFromRFC3066LanguageTag() throws ConversionException
+ {
+ assertEquals(new Locale("en"),
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en"));
+ assertEquals(new Locale("en", "US"),
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en-US"));
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("wrong");
+ fail("Should have failed since an invalid String was passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("zz");
+ fail("Should have failed since an invalid language code was
passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("fr-ZZ");
+ fail("Should have failed since an invalid country code was passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ // weird combination should work as well
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("fr-US");
+ }
+
+ public void testGetRFC3066LanguageTagFromLocale() throws ConversionException
+ {
+ assertEquals("en",
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en")));
+ assertEquals("en-US",
LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en",
"US")));
+ }
+
+ public void testCachingLocaleFormat() throws ConversionException
+ {
+ TestLocaleFormat delegate = new TestLocaleFormat();
+ delegate.put(new Locale("abc"), "abc");
+ CachingLocaleFormat format = new CachingLocaleFormat(delegate);
+
+ //
+ assertEquals(new Locale("abc"), format.getLocale("abc"));
+ assertEquals("abc", format.toString(new Locale("abc")));
+
+ //
+ try
+ {
+ format.getLocale("def");
+ fail();
+ }
+ catch (ConversionException e)
+ {
+ }
+
+ //
+ try
+ {
+ format.toString(new Locale("def"));
+ fail();
+ }
+ catch (ConversionException e)
+ {
+ }
+ }
+
+ private static class TestLocaleFormat extends AbstractLocaleFormat
+ {
+
+ /** . */
+ private final Map localeToString = new HashMap();
+
+ /** . */
+ private final Map stringToLocale = new HashMap();
+
+ private void put(Locale locale, String string)
+ {
+ localeToString.put(locale, string);
+ stringToLocale.put(string, locale);
+ }
+
+ protected Locale internalGetLocale(String value) throws ConversionException
+ {
+ Locale locale = (Locale)stringToLocale.get(value);
+ if (locale == null)
+ {
+ throw new ConversionException();
+ }
+ return locale;
+ }
+
+ protected void internalWrite(Locale locale, Writer writer) throws IOException,
ConversionException
+ {
+ String string = (String)localeToString.get(locale);
+ if (string == null)
+ {
+ throw new ConversionException();
+ }
+ writer.write(string);
+ }
+ }
+
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocalizedStringTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocalizedStringTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocalizedStringTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,89 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.i18n.LocalizedString;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6818 $
+ */
+public class LocalizedStringTestCase extends TestCase
+{
+ private Map<Locale, String> values = new HashMap<Locale, String>();
+ private LocalizedString localizedString;
+
+ protected void setUp() throws Exception
+ {
+ values.put(Locale.ENGLISH, "labour");
+ values.put(Locale.FRENCH, "travail");
+ values.put(Locale.US, "labor");
+ localizedString = new LocalizedString(values, Locale.US);
+ }
+
+ public void testLocalizedStringValuesAreNotModifiable()
+ {
+ try
+ {
+ localizedString.getValues().clear();
+ }
+ catch (Exception expected)
+ {
+ assertTrue(localizedString.hasValues());
+ }
+ }
+
+ public void testPreferredOrBestLocalizedMappingFor()
+ {
+ try
+ {
+ localizedString.getPreferredOrBestLocalizedMappingFor(null);
+ fail("LocalizedString get most appropriate value for should have thrown an
IllegalArgumentException with a null argument");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // no desired locales: should return default
+ checkValueAndLocale(Locale.US, new String[]{});
+
+ checkValueAndLocale(Locale.ENGLISH, new String[]{"en", "en-US",
"aa"});
+ checkValueAndLocale(Locale.US, new String[]{"en-US", "en",
"aa"});
+ checkValueAndLocale(Locale.FRENCH, new String[]{"fr-CA"});
+ }
+
+ private void checkValueAndLocale(Locale locale, String[] desiredLocales)
+ {
+ LocalizedString.Value mapping =
localizedString.getPreferredOrBestLocalizedMappingFor(desiredLocales);
+
+ Locale foundLocale = mapping.getLocale();
+ assertEquals(locale, foundLocale);
+ assertEquals(values.get(foundLocale), mapping.getString());
+ assertEquals(mapping.getString(),
localizedString.getMostAppropriateValueFor(desiredLocales));
+ }
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ParentChildResourceBundleTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ParentChildResourceBundleTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/ParentChildResourceBundleTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,115 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.common.i18n.ParentChildResourceBundle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6818 $
+ */
+public class ParentChildResourceBundleTestCase extends TestCase
+{
+ public ParentChildResourceBundleTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBasic()
+ {
+ ResourceBundle parent = new ResourceBundle()
+ {
+ protected Object handleGetObject(String key)
+ {
+ if ("key-a".equals(key))
+ {
+ return "parent-a";
+ }
+ if ("key-b".equals(key))
+ {
+ return "parent-b";
+ }
+ return null;
+ }
+ public Enumeration getKeys()
+ {
+ Vector keys = new Vector();
+ keys.add("key-a");
+ keys.add("key-b");
+ return keys.elements();
+ }
+ public Locale getLocale()
+ {
+ return Locale.CHINA;
+ }
+ };
+ ResourceBundle child = new ResourceBundle()
+ {
+ protected Object handleGetObject(String key)
+ {
+ if ("key-a".equals(key))
+ {
+ return "child-a";
+ }
+ if ("key-c".equals(key))
+ {
+ return "child-c";
+ }
+ return null;
+ }
+ public Enumeration getKeys()
+ {
+ Vector keys = new Vector();
+ keys.add("key-a");
+ keys.add("key-c");
+ return keys.elements();
+ }
+ public Locale getLocale()
+ {
+ return Locale.GERMAN;
+ }
+ };
+ ResourceBundle bundle = new ParentChildResourceBundle(parent, child);
+ assertEquals(Locale.GERMAN, bundle.getLocale());
+ assertEquals("child-a", bundle.getString("key-a"));
+ assertEquals("parent-b", bundle.getString("key-b"));
+ assertEquals("child-c", bundle.getString("key-c"));
+ Set keys = new HashSet(Arrays.asList(new
Object[]{"key-a","key-b","key-c"}));
+ for (Enumeration e = bundle.getKeys();e.hasMoreElements();)
+ {
+ assertTrue(keys.remove(e.nextElement()));
+ }
+ assertTrue(keys.isEmpty());
+ }
+
+}
Added:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/SimpleResourceBundleTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/SimpleResourceBundleTestCase.java
(rev 0)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/SimpleResourceBundleTestCase.java 2008-01-09
17:17:49 UTC (rev 9467)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.i18n;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.i18n.SimpleResourceBundleFactory;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class SimpleResourceBundleTestCase extends TestCase
+{
+
+ public SimpleResourceBundleTestCase()
+ {
+ }
+
+ public SimpleResourceBundleTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testNormal()
+ {
+ SimpleResourceBundleFactory factory = new
SimpleResourceBundleFactory("a", BundleClassLoader.assertExists());
+ assertNull(factory.getBundle(Locale.UK));
+ ResourceBundle bundle = factory.getBundle(new Locale("fr",
"FR", "ab"));
+ assertNotNull(bundle);
+ assertEquals(Locale.FRANCE, bundle.getLocale());
+ bundle = factory.getBundle(new Locale("fr", "FR"));
+ assertNotNull(bundle);
+ assertEquals(Locale.FRANCE, bundle.getLocale());
+ bundle = factory.getBundle(new Locale("fr"));
+ assertNotNull(bundle);
+ assertEquals(Locale.FRENCH, bundle.getLocale());
+ }
+
+ public void testCtorThrowsIAE()
+ {
+ try
+ {
+ new SimpleResourceBundleFactory(null, BundleClassLoader.assertExists());
+ fail();
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ }
+ try
+ {
+ new SimpleResourceBundleFactory("a", null);
+ fail();
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ }
+ }
+
+ public void testGetBundleWithNullLocaleThrowsIAE()
+ {
+ SimpleResourceBundleFactory factory = new
SimpleResourceBundleFactory("a", BundleClassLoader.assertExists());
+ try
+ {
+ factory.getBundle(null);
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ }
+ }
+}