use of java.util.Locale in project head by mifos.
the class LocalizationConverterTest method testGetDateSeparator.
/**
* Currently broken -- incomplete support for multiple locales for numeric
* input.
*/
@Ignore
@Test
public void testGetDateSeparator() {
String separator = "/";
Locale locale = Localization.getInstance().getConfiguredLocale();
String dateSeparator = converter.getDateSeparatorForCurrentLocale();
if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
Assert.assertEquals(separator, dateSeparator);
}
converter.setCurrentLocale(new Locale("IS", "is"));
dateSeparator = converter.getDateSeparatorForCurrentLocale();
Assert.assertEquals(".", dateSeparator);
converter.setCurrentLocale(locale);
}
use of java.util.Locale in project head by mifos.
the class LocalizationConverterTest method testGetDoubleValueForCurrentLocale.
/*
* get convert a string to a double to the config locale and the format is
* the money format 7.1
*/
@Test
public void testGetDoubleValueForCurrentLocale() {
String doubleValueString = "223.59";
Double dValue = 223.59;
Locale locale = Localization.getInstance().getConfiguredLocale();
Double dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
Assert.assertEquals(dNumber, dValue);
// if the wrong decimal separator is entered, it will throw
// exception
doubleValueString = "223,59";
try {
dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
} catch (Exception ex) {
Assert.assertTrue(ex.getMessage().startsWith("The format of the number is invalid."));
}
}
converter.setCurrentLocale(new Locale("IS", "is"));
doubleValueString = "223,59";
dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
Assert.assertEquals(dNumber, dValue);
// if the wrong decimal separator is entered, it will throw exception
doubleValueString = "223.59";
try {
dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
} catch (Exception ex) {
Assert.assertTrue(ex.getMessage().startsWith("The format of the number is invalid."));
}
converter.setCurrentLocale(locale);
}
use of java.util.Locale in project head by mifos.
the class LocalizationConverterTest method testGetDoubleStringForInterest.
@Test
public void testGetDoubleStringForInterest() {
String doubleValueString = "2123.12345";
Double dValue = 2123.12345000000;
Locale locale = Localization.getInstance().getConfiguredLocale();
String dString = converter.getDoubleStringForInterest(dValue);
if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
Assert.assertEquals(doubleValueString, dString);
}
converter.setCurrentLocale(new Locale("IS", "is"));
doubleValueString = "2123,12345";
dString = converter.getDoubleStringForInterest(dValue);
Assert.assertEquals(doubleValueString, dString);
converter.setCurrentLocale(locale);
}
use of java.util.Locale in project head by mifos.
the class BundleKeyTest method testEqualsObject.
public void testEqualsObject() {
Assert.assertTrue(bundleKey.equals(bundleKey));
Assert.assertFalse(bundleKey.equals(null));
Locale locale = new Locale("EN");
Assert.assertFalse(bundleKey.equals(new BundleKey(locale, "wrongKey")));
locale = new Locale("SP");
Assert.assertFalse(bundleKey.equals(new BundleKey(locale, "Key")));
}
use of java.util.Locale in project head by mifos.
the class DateFormatter method exec.
/**
* @param args
* a list of arguments passed in from FTL in this order:
* <ul>
* <li>date object to be formatted. It can be an instance of either java.util.Date,
* org.joda.time.DateTime or org.joda.time.LocalDate</li>
* <li>pattern: date format pattern see {@link java.text.SimpleDateFormat}</li>
* <li>locale: an instance of java.util.Locale</li>
* </ul>
*/
@Override
public Object exec(List args) throws TemplateModelException {
if (args.size() != 3) {
throw new IllegalArgumentException("Wrong arguments");
}
Object date = DeepUnwrap.unwrap((TemplateModel) args.get(0));
String pattern = (String) DeepUnwrap.unwrap((TemplateModel) args.get(1));
Locale locale = (Locale) DeepUnwrap.unwrap((TemplateModel) args.get(2));
if (date instanceof LocalDate) {
date = ((LocalDate) date).toDateTimeAtStartOfDay();
}
String formatted = "";
if (date instanceof DateTime) {
formatted = DateTimeFormat.forPattern(pattern).withLocale(locale).print((DateTime) date);
} else if (date instanceof Date) {
formatted = new SimpleDateFormat(pattern, locale).format((Date) date);
} else if (date != null) {
throw new IllegalArgumentException("Unsupported date type: " + date.getClass());
}
return formatted;
}
Aggregations