use of org.javarosa.core.services.locale.Localizer 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.Localizer in project javarosa by opendatakit.
the class LocalizerTest method testSetToDefaultNoDefault.
public void testSetToDefaultNoDefault() {
Localizer l = new Localizer();
final String TEST_LOCALE = "test";
l.addAvailableLocale(TEST_LOCALE);
try {
l.setToDefault();
fail("Set current locale to default when no default set");
} catch (IllegalStateException ise) {
// expected
}
}
use of org.javarosa.core.services.locale.Localizer 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.Localizer 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
}
}
use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.
the class TextFormTests method testTextForms.
/**
* Test that the long and short text forms work as expected
* (fallback to default for example).
* Test being able to retrieve other exotic forms
*/
public void testTextForms() {
FormEntryController fec = fpi.getFormEntryController();
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
boolean foundFlag = false;
Localizer l = fpi.getFormDef().getLocalizer();
l.setDefaultLocale(l.getAvailableLocales()[0]);
l.setLocale(l.getAvailableLocales()[0]);
int state = -99;
while (state != FormEntryController.EVENT_QUESTION) {
state = fec.stepToNextEvent();
}
fep = fec.getModel().getQuestionPrompt();
if (!fep.getLongText().equals("Patient ID"))
fail("getLongText() not returning correct value");
if (!fep.getShortText().equals("ID"))
fail("getShortText() not returning correct value");
if (!fep.getAudioText().equals("jr://audio/hah.mp3"))
fail("getAudioText() not returning correct value");
state = -99;
while (state != FormEntryController.EVENT_QUESTION) {
state = fec.stepToNextEvent();
}
fep = fec.getModel().getQuestionPrompt();
if (!fep.getShortText().equals("Name"))
fail("getShortText() not returning correct value");
if (!fep.getLongText().equals("Full Name"))
fail("getLongText() not falling back to default text form correctly");
String v = fep.getSpecialFormQuestionText("long");
if (fep.getSpecialFormQuestionText("long") != null)
fail("getSpecialFormQuestionText() returning incorrect value");
}
Aggregations