use of android.icu.util.CurrencyAmount in project j2objc by google.
the class NumberFormatTest method TestCurrencyAmountCoverage.
@Test
public void TestCurrencyAmountCoverage() {
CurrencyAmount ca, cb;
try {
ca = new CurrencyAmount(null, null);
errln("NullPointerException should have been thrown.");
} catch (NullPointerException ex) {
}
try {
ca = new CurrencyAmount(new Integer(0), null);
errln("NullPointerException should have been thrown.");
} catch (NullPointerException ex) {
}
ca = new CurrencyAmount(new Integer(0), Currency.getInstance(new ULocale("ja_JP")));
cb = new CurrencyAmount(new Integer(1), Currency.getInstance(new ULocale("ja_JP")));
if (ca.equals(null)) {
errln("Comparison should return false.");
}
if (!ca.equals(ca)) {
errln("Comparision should return true.");
}
if (ca.equals(cb)) {
errln("Comparison should return false.");
}
}
use of android.icu.util.CurrencyAmount in project j2objc by google.
the class NumberFormatTest method TestFormat.
/*
* Testing the method public StringBuffer format(Object number, ...)
*/
@Test
public void TestFormat() {
NumberFormat nf = NumberFormat.getInstance();
StringBuffer sb = new StringBuffer("dummy");
FieldPosition fp = new FieldPosition(0);
// Tests when "if (number instanceof Long)" is true
try {
nf.format(new Long("0"), sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "return an exception for a Long object. Error: " + e);
}
// Tests when "else if (number instanceof BigInteger)" is true
try {
nf.format((Object) new BigInteger("0"), sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "return an exception for a BigInteger object. Error: " + e);
}
// Tests when "else if (number instanceof java.math.BigDecimal)" is true
try {
nf.format((Object) new java.math.BigDecimal("0"), sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "return an exception for a java.math.BigDecimal object. Error: " + e);
}
// Tests when "else if (number instanceof android.icu.math.BigDecimal)" is true
try {
nf.format((Object) new android.icu.math.BigDecimal("0"), sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "return an exception for a android.icu.math.BigDecimal object. Error: " + e);
}
// Tests when "else if (number instanceof CurrencyAmount)" is true
try {
CurrencyAmount ca = new CurrencyAmount(0.0, Currency.getInstance(new ULocale("en_US")));
nf.format((Object) ca, sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "return an exception for a CurrencyAmount object. Error: " + e);
}
// Tests when "else if (number instanceof Number)" is true
try {
nf.format(0.0, sb, fp);
} catch (Exception e) {
errln("NumberFormat.format(Object number, ...) was not suppose to " + "to return an exception for a Number object. Error: " + e);
}
// Tests when "else" is true
try {
nf.format(new Object(), sb, fp);
errln("NumberFormat.format(Object number, ...) was suppose to " + "return an exception for an invalid object.");
} catch (Exception e) {
}
try {
nf.format(new String("dummy"), sb, fp);
errln("NumberFormat.format(Object number, ...) was suppose to " + "return an exception for an invalid object.");
} catch (Exception e) {
}
}
use of android.icu.util.CurrencyAmount in project j2objc by google.
the class NumberFormatTest method TestCurrencyFormatForMixParsing.
@Test
public void TestCurrencyFormatForMixParsing() {
MeasureFormat curFmt = MeasureFormat.getCurrencyFormat(new ULocale("en_US"));
String[] formats = { // string to be parsed
"$1,234.56", "USD1,234.56", "US dollars1,234.56", "1,234.56 US dollars" };
try {
for (int i = 0; i < formats.length; ++i) {
String stringToBeParsed = formats[i];
CurrencyAmount parsedVal = (CurrencyAmount) curFmt.parseObject(stringToBeParsed);
Number val = parsedVal.getNumber();
if (!val.equals(new BigDecimal("1234.56"))) {
errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number. val=" + val);
}
if (!parsedVal.getCurrency().equals(Currency.getInstance("USD"))) {
errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the currency");
}
}
} catch (ParseException e) {
errln("parse FAILED: " + e.toString());
}
}
use of android.icu.util.CurrencyAmount in project j2objc by google.
the class CompactDecimalFormatTest method TestBug12422.
@Test
public void TestBug12422() {
CompactDecimalFormat cdf;
String result;
// Bug #12422
cdf = CompactDecimalFormat.getInstance(new ULocale("ar", "SA"), CompactDecimalFormat.CompactStyle.LONG);
result = cdf.format(43000);
assertEquals("CDF should correctly format 43000 in 'ar'", "٤٣ ألف", result);
// Bug #12449
cdf = CompactDecimalFormat.getInstance(new ULocale("ar"), CompactDecimalFormat.CompactStyle.SHORT);
cdf.setMaximumSignificantDigits(3);
result = cdf.format(1234);
assertEquals("CDF should correctly format 1234 with 3 significant digits in 'ar'", "١٫٢٣ ألف", result);
// Check currency formatting as well
cdf = CompactDecimalFormat.getInstance(new ULocale("ar"), CompactDecimalFormat.CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format 43000 with currency in 'ar'", "US$ ٤٣ ألف", result);
result = cdf.format(new CurrencyAmount(-43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format -43000 with currency in 'ar'", "US$ -٤٣ ألف", result);
// Extra locale with different positive/negative formats
cdf = CompactDecimalFormat.getInstance(new ULocale("fi"), CompactDecimalFormat.CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format 43000 with currency in 'fi'", "43 t. $", result);
result = cdf.format(new CurrencyAmount(-43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format -43000 with currency in 'fi'", "−43 t. $", result);
}
Aggregations