use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testAvailableLocales.
public void testAvailableLocales() {
Localizer l = new Localizer();
String[] locales;
l.addAvailableLocale("test1");
locales = l.getAvailableLocales();
if (locales.length != 1 || !locales[0].equals("test1")) {
fail("Available locales not as expected");
}
l.addAvailableLocale("test2");
locales = l.getAvailableLocales();
if (locales.length != 2 || !locales[0].equals("test1") || !locales[1].equals("test2")) {
fail("Available locales not as expected");
}
l.addAvailableLocale("test3");
locales = l.getAvailableLocales();
if (locales.length != 3 || !locales[0].equals("test1") || !locales[1].equals("test2") || !locales[2].equals("test3")) {
fail("Available locales not as expected");
}
l.destroyLocale("test2");
locales = l.getAvailableLocales();
if (locales.length != 2 || !locales[0].equals("test1") || !locales[1].equals("test3")) {
fail("Available locales not as expected");
}
l.destroyLocale("test1");
locales = l.getAvailableLocales();
if (locales.length != 1 || !locales[0].equals("test3")) {
fail("Available locales not as expected");
}
l.destroyLocale("test3");
locales = l.getAvailableLocales();
if (locales == null || locales.length != 0) {
fail("Available locales not as expected");
}
}
use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testSerialization.
public void testSerialization() {
Localizer l = new Localizer(true, true);
TableLocaleSource firstLocale = new TableLocaleSource();
TableLocaleSource secondLocale = new TableLocaleSource();
TableLocaleSource finalLocale = new TableLocaleSource();
testSerialize(l, "empty 1");
testSerialize(new Localizer(false, false), "empty 2");
testSerialize(new Localizer(true, false), "empty 3");
testSerialize(new Localizer(false, true), "empty 4");
l.addAvailableLocale("locale1");
testSerialize(l, "one empty locale");
l.addAvailableLocale("locale2");
testSerialize(l, "two empty locales");
l.setDefaultLocale("locale2");
testSerialize(l, "two empty locales + default");
l.setToDefault();
testSerialize(l, "two empty locales + default/current");
l.setLocale("locale1");
testSerialize(l, "two empty locales + default/current 2");
l.setDefaultLocale(null);
testSerialize(l, "two empty locales + current");
l.registerLocaleResource("locale1", firstLocale);
l.registerLocaleResource("locale2", secondLocale);
firstLocale.setLocaleMapping("id1", "text1");
testSerialize(l, "locales with data 1");
firstLocale.setLocaleMapping("id2", "text2");
testSerialize(l, "locales with data 2");
secondLocale.setLocaleMapping("id1", "text1");
secondLocale.setLocaleMapping("id2", "text2");
secondLocale.setLocaleMapping("id3", "text3");
testSerialize(l, "locales with data 3");
secondLocale.setLocaleMapping("id2", null);
testSerialize(l, "locales with data 4");
finalLocale.setLocaleMapping("id1", "text1");
finalLocale.setLocaleMapping("id4", "text4");
l.registerLocaleResource("locale3", finalLocale);
testSerialize(l, "locales with data 5");
l.destroyLocale("locale2");
testSerialize(l, "locales with data 6");
}
use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testDestroyCurrentLocale.
public void testDestroyCurrentLocale() {
Localizer l = new Localizer();
final String TEST_LOCALE = "test";
l.addAvailableLocale(TEST_LOCALE);
l.setLocale(TEST_LOCALE);
try {
l.destroyLocale(TEST_LOCALE);
fail("Destroyed current locale");
} catch (IllegalArgumentException iae) {
// expected
}
}
use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testAddExistingLocale.
public void testAddExistingLocale() {
Localizer l = new Localizer();
final String TEST_LOCALE = "test";
l.addAvailableLocale(TEST_LOCALE);
TableLocaleSource table = new TableLocaleSource();
table.setLocaleMapping("textID", "text");
l.registerLocaleResource(TEST_LOCALE, table);
OrderedMap<String, String> localeData = l.getLocaleData(TEST_LOCALE);
boolean result = l.addAvailableLocale(TEST_LOCALE);
if (result) {
fail("Localizer overwrote existing locale");
}
OrderedMap<String, String> newLocaleData = l.getLocaleData(TEST_LOCALE);
if (!localeData.equals(newLocaleData)) {
fail("Localizer overwrote existing locale");
}
}
use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testTextMappingOverwrite.
public void testTextMappingOverwrite() {
Localizer l = new Localizer();
final String TEST_LOCALE = "test";
l.addAvailableLocale(TEST_LOCALE);
TableLocaleSource table = new TableLocaleSource();
table.setLocaleMapping("textID", "oldText");
table.setLocaleMapping("textID", "newText");
l.registerLocaleResource(TEST_LOCALE, table);
if (!l.hasMapping(TEST_LOCALE, "textID")) {
fail("Localizer does not contain overwritten text mapping");
}
if (!"newText".equals(l.getLocaleData(TEST_LOCALE).get("textID"))) {
fail("Newly overwritten text mapping does not match source");
}
}
Aggregations