use of java.util.Currency in project robovm by robovm.
the class OldNumberFormatTest method test_setCurrencyLjava_util_Currency.
public void test_setCurrencyLjava_util_Currency() {
// Test for method void setCurrency(java.util.Currency)
// a subclass that supports currency formatting
Currency currA = Currency.getInstance("ARS");
NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
format.setCurrency(currA);
assertSame("Returned incorrect currency", currA, format.getCurrency());
// a subclass that doesn't support currency formatting
ChoiceFormat cformat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
try {
((NumberFormat) cformat).setCurrency(currA);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
try {
NumberFormat.getInstance().setCurrency(null);
fail("NullPointerException was thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
NumberFormat.getIntegerInstance().setCurrency(null);
fail("NullPointerException was thrown.");
} catch (NullPointerException npe) {
//expected
}
}
use of java.util.Currency in project robovm by robovm.
the class OldAndroidLocaleTest method testICULocales.
// This one makes sure we have all necessary locales installed.
public void testICULocales() {
String[] locales = new String[] { // List of locales currently required for Android.
"en_US", "es_US", "en_GB", "fr_FR", "de_DE", "de_AT", "cs_CZ", "nl_NL" };
String[] mondays = new String[] { "Monday", "lunes", "Monday", "lundi", "Montag", "Montag", "pondělí", "maandag" };
String[] currencies = new String[] { "USD", "USD", "GBP", "EUR", "EUR", "EUR", "CZK", "EUR" };
for (int i = 0; i < locales.length; i++) {
Locale l = new Locale(locales[i].substring(0, 2), locales[i].substring(3));
// Check language part of locale.
DateFormatSymbols d = new DateFormatSymbols(l);
assertEquals("Monday name for " + locales[i] + " must match", mondays[i], d.getWeekdays()[2]);
// Check country part of locale.
Currency c = Currency.getInstance(l);
assertEquals("Currency code for " + locales[i] + " must match", currencies[i], c.getCurrencyCode());
}
}
use of java.util.Currency in project robovm by robovm.
the class CurrencyTest method test_getInstanceLjava_util_Locale.
/**
* java.util.Currency#getInstance(java.util.Locale)
*/
public void test_getInstanceLjava_util_Locale() {
/*
* the behaviour in all these three cases should be the same since this
* method ignores language and variant component of the locale.
*/
Currency c0 = Currency.getInstance("CAD");
Currency c1 = Currency.getInstance(new Locale("en", "CA"));
assertTrue("Currency.getInstance(new Locale(\"en\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c1 == c0);
Currency c2 = Currency.getInstance(new Locale("fr", "CA"));
assertTrue("Currency.getInstance(new Locale(\"fr\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c2 == c0);
Currency c3 = Currency.getInstance(new Locale("", "CA"));
assertTrue("Currency.getInstance(new Locale(\"\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c3 == c0);
c0 = Currency.getInstance("JPY");
c1 = Currency.getInstance(new Locale("ja", "JP"));
assertTrue("Currency.getInstance(new Locale(\"ja\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c1 == c0);
c2 = Currency.getInstance(new Locale("", "JP"));
assertTrue("Currency.getInstance(new Locale(\"\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c2 == c0);
c3 = Currency.getInstance(new Locale("bogus", "JP"));
assertTrue("Currency.getInstance(new Locale(\"bogus\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c3 == c0);
Locale localeGu = new Locale("gu", "IN");
Currency cGu = Currency.getInstance(localeGu);
Locale localeKn = new Locale("kn", "IN");
Currency cKn = Currency.getInstance(localeKn);
assertTrue("Currency.getInstance(Locale_" + localeGu.toString() + "))" + "isn't equal to " + "Currency.getInstance(Locale_" + localeKn.toString() + "))", cGu == cKn);
// some teritories do not have currencies, like Antarctica
Locale loc = new Locale("", "AQ");
try {
Currency curr = Currency.getInstance(loc);
assertNull("Currency.getInstance(new Locale(\"\", \"AQ\")) did not return null", curr);
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException " + e);
}
// unsupported/legacy iso3 countries
loc = new Locale("", "ZR");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "ZAR");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "FX");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "FXX");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of java.util.Currency in project robovm by robovm.
the class CurrencyTest method test_getSymbol.
/**
* java.util.Currency#getSymbol()
*/
public void test_getSymbol() {
Currency currK = Currency.getInstance("KRW");
Currency currI = Currency.getInstance("IEP");
Currency currUS = Currency.getInstance("USD");
Locale.setDefault(Locale.US);
// BEGIN android-changed
// KRW currency symbol is ₩ since CLDR1.7 release.
assertEquals("currK.getSymbol()", "₩", currK.getSymbol());
// IEP currency symbol is IEP since CLDR2.0 release.
assertEquals("currI.getSymbol()", "IEP", currI.getSymbol());
// END android-changed
assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
Locale.setDefault(new Locale("en", "IE"));
// BEGIN android-changed
assertEquals("currK.getSymbol()", "₩", currK.getSymbol());
assertEquals("currI.getSymbol()", "IEP", currI.getSymbol());
assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
// END android-changed
// test what happens if this is an invalid locale,
// one with Korean country but an India language
Locale.setDefault(new Locale("kr", "KR"));
// BEGIN android-changed
assertEquals("currK.getSymbol()", "₩", currK.getSymbol());
assertEquals("currI.getSymbol()", "IEP", currI.getSymbol());
// END android-changed
assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
}
use of java.util.Currency in project robovm by robovm.
the class CurrencyTest method test_getSymbolLjava_util_Locale.
/**
* java.util.Currency#getSymbol(java.util.Locale)
*/
public void test_getSymbolLjava_util_Locale() {
//Tests was simplified because java specification not
// includes strong requirements for returnig symbol.
// on android platform used wrong character for yen
// sign: ¥ instead of ¥
Locale[] desiredLocales = new Locale[] { Locale.JAPAN, Locale.JAPANESE, Locale.FRANCE, Locale.FRENCH, Locale.US, Locale.UK, Locale.CANADA, Locale.CANADA_FRENCH, Locale.ENGLISH, new Locale("ja", "JP"), new Locale("", "JP"), new Locale("fr", "FR"), new Locale("", "FR"), new Locale("en", "US"), new Locale("", "US"), new Locale("es", "US"), new Locale("ar", "US"), new Locale("ja", "US"), new Locale("en", "CA"), new Locale("fr", "CA"), new Locale("", "CA"), new Locale("ar", "CA"), new Locale("ja", "JP"), new Locale("", "JP"), new Locale("ar", "JP"), new Locale("ja", "AE"), new Locale("en", "AE"), new Locale("ar", "AE"), new Locale("da", "DK"), new Locale("", "DK"), new Locale("da", ""), new Locale("ja", ""), new Locale("en", "") };
Set<Locale> availableLocales = new HashSet<Locale>(Arrays.asList(Locale.getAvailableLocales()));
ArrayList<Locale> locales = new ArrayList<Locale>();
for (Locale desiredLocale : desiredLocales) {
if (availableLocales.contains(desiredLocale)) {
locales.add(desiredLocale);
}
}
Locale[] loc1 = locales.toArray(new Locale[locales.size()]);
String[] euro = new String[] { "EUR", "€" };
// ¥ and ¥ are actually the same symbol, just different code points.
// But the RI returns the ¥ and Android returns those with ¥
String[] yen = new String[] { "JPY", "¥", "¥JP", "JP¥", "¥", "¥JP", "JP¥" };
String[] dollar = new String[] { "USD", "$", "US$", "$US" };
// BEGIN android-changed
// Starting CLDR 1.7 release, currency symbol for CAD changed to CA$ in some locales such as ja.
String[] cDollar = new String[] { "CA$", "CAD", "$", "Can$", "$CA" };
// END android-changed
Currency currE = Currency.getInstance("EUR");
Currency currJ = Currency.getInstance("JPY");
Currency currUS = Currency.getInstance("USD");
Currency currCA = Currency.getInstance("CAD");
int i, j, k;
boolean flag;
for (k = 0; k < loc1.length; k++) {
Locale.setDefault(loc1[k]);
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < euro.length; j++) {
if (currE.getSymbol(loc1[i]).equals(euro[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Euro currency returned " + currE.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(euro), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < yen.length; j++) {
byte[] b1 = null;
byte[] b2 = null;
if (currJ.getSymbol(loc1[i]).equals(yen[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Yen currency returned " + currJ.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(yen), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < dollar.length; j++) {
if (currUS.getSymbol(loc1[i]).equals(dollar[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Dollar currency returned " + currUS.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(dollar), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < cDollar.length; j++) {
if (currCA.getSymbol(loc1[i]).equals(cDollar[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Canadian Dollar currency returned " + currCA.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(cDollar), flag);
}
}
}
Aggregations