use of org.javarosa.core.services.locale.TableLocaleSource 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.TableLocaleSource 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");
}
}
use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.
the class LocalizerTest method testNullArgs.
public void testNullArgs() {
Localizer l = new Localizer();
l.addAvailableLocale("test");
TableLocaleSource table = new TableLocaleSource();
try {
l.addAvailableLocale(null);
fail("addAvailableLocale: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
if (l.hasLocale(null)) {
fail("Localizer reports it contains null locale");
}
try {
l.registerLocaleResource(null, new TableLocaleSource());
fail("setLocaleData: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
try {
l.registerLocaleResource("test", null);
fail("setLocaleData: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
if (l.getLocaleData(null) != null) {
fail("getLocaleData: Localizer returns mappings for null locale");
}
try {
l.getLocaleMap(null);
fail("getLocaleMap: Did not get expected exception");
} catch (UnregisteredLocaleException nsee) {
// expected
}
try {
table.setLocaleMapping(null, "text");
fail("setLocaleMapping: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
try {
table.setLocaleMapping(null, null);
fail("setLocaleMapping: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
try {
l.hasMapping(null, "textID");
fail("hasMapping: Did not get expected exception");
} catch (UnregisteredLocaleException nsee) {
// expected
}
if (l.hasMapping("test", null)) {
fail("Localization reports it contains null mapping");
}
try {
l.destroyLocale(null);
fail("destroyLocale: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
try {
l.getText("textID", (String) null);
fail("getText: Did not get expected exception");
} catch (UnregisteredLocaleException nsee) {
// expected
}
try {
l.getText(null, "test");
fail("getText: Did not get expected null pointer exception");
} catch (NullPointerException npe) {
// expected
}
}
use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.
the class LocalizerTest method testFallbacks.
public void testFallbacks() {
Localizer localizer = new Localizer(true, true);
localizer.addAvailableLocale("one");
localizer.addAvailableLocale("two");
TableLocaleSource firstLocale = new TableLocaleSource();
firstLocale.setLocaleMapping("data", "val");
firstLocale.setLocaleMapping("data2", "vald2");
localizer.registerLocaleResource("one", firstLocale);
TableLocaleSource secondLocale = new TableLocaleSource();
firstLocale.setLocaleMapping("data", "val2");
localizer.registerLocaleResource("two", secondLocale);
localizer.setDefaultLocale("one");
localizer.setLocale("two");
String text = localizer.getText("data2");
assertEquals("fallback", text, "vald2");
String shouldBeNull = localizer.getText("noexist");
assertNull("Localizer didn't return null value", shouldBeNull);
localizer.setToDefault();
shouldBeNull = localizer.getText("noexist");
assertNull("Localizer didn't return null value", shouldBeNull);
assertNull("Localizer didn't return null value", shouldBeNull);
}
use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.
the class LocalizerTest method testGetTextNoCurrentLocale.
public void testGetTextNoCurrentLocale() {
Localizer l = new Localizer();
TableLocaleSource table = new TableLocaleSource();
l.addAvailableLocale("test");
l.setDefaultLocale("test");
table.setLocaleMapping("textID", "text");
l.registerLocaleResource("test", table);
try {
l.getText("textID");
fail("Retrieved current locale text when current locale not set");
} catch (UnregisteredLocaleException nsee) {
// expected
}
}
Aggregations