new CollationServiceTest().run(args);
}
public void TestRegister() {
// register a singleton
Collator frcol = Collator.getInstance(ULocale.FRANCE);
Collator uscol = Collator.getInstance(ULocale.US);
{ // try override en_US collator
Object key = Collator.registerInstance(frcol, ULocale.US);
Collator ncol = Collator.getInstance(ULocale.US);
if (!frcol.equals(ncol)) {
errln("register of french collator for en_US failed");
}
// coverage
Collator test = Collator.getInstance(ULocale.GERMANY); // CollatorFactory.handleCreate
if (!test.getLocale(ULocale.VALID_LOCALE).equals(ULocale.GERMANY)) {
errln("Collation from Germany is really " + test.getLocale(ULocale.VALID_LOCALE));
}
if (!Collator.unregister(key)) {
errln("failed to unregister french collator");
}
ncol = Collator.getInstance(ULocale.US);
if (!uscol.equals(ncol)) {
errln("collator after unregister does not match original");
}
}
ULocale fu_FU = new ULocale("fu_FU_FOO");
{ // try create collator for new locale
Collator fucol = Collator.getInstance(fu_FU);
Object key = Collator.registerInstance(frcol, fu_FU);
Collator ncol = Collator.getInstance(fu_FU);
if (!frcol.equals(ncol)) {
errln("register of fr collator for fu_FU failed");
}
ULocale[] locales = Collator.getAvailableULocales();
boolean found = false;
for (int i = 0; i < locales.length; ++i) {
if (locales[i].equals(fu_FU)) {
found = true;
break;
}
}
if (!found) {
errln("new locale fu_FU not reported as supported locale");
}
try{
String name = Collator.getDisplayName(fu_FU);
if (!"fu (FU, FOO)".equals(name)) {
errln("found " + name + " for fu_FU");
}
}catch(MissingResourceException ex){
warnln("Could not load locale data.");
}
try{
String name = Collator.getDisplayName(fu_FU, fu_FU);
if (!"fu (FU, FOO)".equals(name)) {
errln("found " + name + " for fu_FU");
}
}catch(MissingResourceException ex){
warnln("Could not load locale data.");
}
if (!Collator.unregister(key)) {
errln("failed to unregister french collator");
}
ncol = Collator.getInstance(fu_FU);
if (!fucol.equals(ncol)) {
errln("collator after unregister does not match original fu_FU");
}
}
{
// coverage after return to default
ULocale[] locales = Collator.getAvailableULocales();
for (int i = 0; i < locales.length; ++i) {
if (locales[i].equals(fu_FU)) {
errln("new locale fu_FU not reported as supported locale");
break;
}
}
Collator ncol = Collator.getInstance(ULocale.US);
if (!ncol.getLocale(ULocale.VALID_LOCALE).equals(ULocale.US)) {
errln("Collation from US is really " + ncol.getLocale(ULocale.VALID_LOCALE));
}
}
}