You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2009/12/16 13:58:46 UTC
svn commit: r891223 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java
src/org/apache/wookie/util/LocalizationUtils.java
Author: scottbw
Date: Wed Dec 16 12:58:45 2009
New Revision: 891223
URL: http://svn.apache.org/viewvc?rev=891223&view=rev
Log:
Checked for null and empty values and consistent output from localization util methods, and added additional test cases
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java
incubator/wookie/trunk/src/org/apache/wookie/util/LocalizationUtils.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java?rev=891223&r1=891222&r2=891223&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/LocalizationUtilsTest.java Wed Dec 16 12:58:45 2009
@@ -35,6 +35,7 @@
public static final String[] LANG_LIST_7 = {null, "za", "fr", "nl"};
public static final String[] LANG_LIST_8 = {"en-us-POSIX"};
public static final String[] LANG_LIST_9 = {null, "en", "en-gb", "en-US-POSIX"};
+ public static final String[] LANG_LIST_10 = {"de"};
public ILocalizedElement[] elements(String[] langs){
ArrayList<ILocalizedElement> licenses = new ArrayList<ILocalizedElement>();
@@ -47,23 +48,49 @@
}
@Test
+ public void nullTest1(){
+ ILocalizedElement[] elements = elements(LANG_LIST_1);
+ elements = LocalizationUtils.processElementsByLocales(elements,null);
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
+ }
+
+ @Test
+ public void nullTest2(){
+ ILocalizedElement[] elements = elements(LANG_LIST_1);
+ elements = LocalizationUtils.processElementsByLocales(elements,new String[]{null});
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
+ }
+
+ @Test
+ public void nullTest3(){
+ ILocalizedElement[] elements = elements(LANG_LIST_1);
+ elements = LocalizationUtils.processElementsByLocales(elements,new String[]{null,null,""});
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
+ }
+
+ @Test
public void defaultOrder1(){
ILocalizedElement[] elements = elements(LANG_LIST_1);
elements = LocalizationUtils.processElementsByDefaultLocales(elements);
- assertEquals(null, elements[3].getLang());
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
}
@Test
public void defaultOrder2(){
ILocalizedElement[] elements = elements(LANG_LIST_2);
elements = LocalizationUtils.processElementsByDefaultLocales(elements);
- assertEquals(null, elements[3].getLang());
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
}
@Test
public void defaultOrder3(){
ILocalizedElement[] elements = elements(LANG_LIST_3);
elements = LocalizationUtils.processElementsByDefaultLocales(elements);
- assertEquals(null, elements[2].getLang());
- assertEquals(null, elements[3].getLang());
+ assertEquals("en", elements[0].getLang());
+ assertEquals(1, elements.length);
}
@Test
@@ -99,10 +126,19 @@
@Test
public void noMatch2(){
ILocalizedElement[] elements = elements(LANG_LIST_1);
+ elements = LocalizationUtils.processElementsByLocales(elements, LANG_LIST_10);
+ assertEquals(null, elements[0].getLang());
+ assertEquals(1, elements.length);
+ }
+
+ @Test
+ public void noMatch1(){
+ ILocalizedElement[] elements = elements(LANG_LIST_2);
elements = LocalizationUtils.processElementsByLocales(elements, LANG_LIST_4);
assertEquals(1, elements.length);
}
+
@Test
public void specifiedOrderM4(){
ILocalizedElement[] elements = elements(LANG_LIST_3);
Modified: incubator/wookie/trunk/src/org/apache/wookie/util/LocalizationUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/LocalizationUtils.java?rev=891223&r1=891222&r2=891223&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/LocalizationUtils.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/LocalizationUtils.java Wed Dec 16 12:58:45 2009
@@ -62,8 +62,9 @@
* @return
*/
public static ILocalizedElement[] processElementsByDefaultLocales(ILocalizedElement[] elements){
- Arrays.sort(elements, new LocaleComparator(getDefaultLocaleList()));
- return elements;
+ List<ULocale> localesList = getDefaultLocaleList();
+ Arrays.sort(elements, new LocaleComparator(localesList));
+ return filter(elements,localesList);
}
/**
@@ -141,9 +142,13 @@
ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
for (String locale:locales){
- ULocale ulocale = ULocale.forLanguageTag(locale);
- ulocales.add(ulocale);
+ if (locale != null){
+ ULocale ulocale = ULocale.forLanguageTag(locale);
+ if (!ulocale.getLanguage().equals(""))
+ ulocales.add(ulocale);
+ }
}
+ if (ulocales.isEmpty()) return getDefaultLocaleList();
prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
return prefs.getLocales();
}