Search in sources :

Example 21 with Currency

use of android.icu.util.Currency in project j2objc by google.

the class CurrencyTest method testGetName_Locale_Int_String_BooleanArray.

@Test
public void testGetName_Locale_Int_String_BooleanArray() {
    Currency currency = Currency.getInstance(ULocale.CHINA);
    boolean[] isChoiceFormat = new boolean[1];
    int nameStyle = Currency.LONG_NAME;
    String pluralCount = "";
    String ulocaleName = currency.getName(ULocale.CANADA, nameStyle, pluralCount, isChoiceFormat);
    assertEquals("currency name mismatch", "Chinese Yuan", ulocaleName);
    String localeName = currency.getName(Locale.CANADA, nameStyle, pluralCount, isChoiceFormat);
    assertEquals("currency name mismatch", ulocaleName, localeName);
}
Also used : Currency(android.icu.util.Currency) Test(org.junit.Test)

Example 22 with Currency

use of android.icu.util.Currency in project j2objc by google.

the class CurrencyTest method TestGetNumericCode.

/**
 * Test case for getNumericCode()
 */
@Test
public void TestGetNumericCode() {
    final Object[][] NUMCODE_TESTDATA = { { "USD", 840 }, { "Usd", 840 }, /* mixed casing */
    { "EUR", 978 }, { "JPY", 392 }, { "XFU", 0 }, /* XFU: no numeric code */
    { "ZZZ", 0 } /* ZZZ: undefined ISO currency code */
    };
    for (Object[] data : NUMCODE_TESTDATA) {
        Currency cur = Currency.getInstance((String) data[0]);
        int numCode = cur.getNumericCode();
        int expected = ((Integer) data[1]).intValue();
        if (numCode != expected) {
            errln("FAIL: getNumericCode returned " + numCode + " for " + cur.getCurrencyCode() + " - expected: " + expected);
        }
    }
}
Also used : Currency(android.icu.util.Currency) Test(org.junit.Test)

Example 23 with Currency

use of android.icu.util.Currency in project j2objc by google.

the class CurrencyTest method TestAPI.

/**
 * Test of basic API.
 */
@Test
public void TestAPI() {
    Currency usd = Currency.getInstance("USD");
    /*int hash = */
    usd.hashCode();
    Currency jpy = Currency.getInstance("JPY");
    if (usd.equals(jpy)) {
        errln("FAIL: USD == JPY");
    }
    if (usd.equals("abc")) {
        errln("FAIL: USD == (String)");
    }
    if (usd.equals(null)) {
        errln("FAIL: USD == (null)");
    }
    if (!usd.equals(usd)) {
        errln("FAIL: USD != USD");
    }
    try {
        Currency nullCurrency = Currency.getInstance((String) null);
        errln("FAIL: Expected getInstance(null) to throw " + "a NullPointerException, but returned " + nullCurrency);
    } catch (NullPointerException npe) {
        logln("PASS: getInstance(null) threw a NullPointerException");
    }
    try {
        Currency bogusCurrency = Currency.getInstance("BOGUS");
        errln("FAIL: Expected getInstance(\"BOGUS\") to throw " + "an IllegalArgumentException, but returned " + bogusCurrency);
    } catch (IllegalArgumentException iae) {
        logln("PASS: getInstance(\"BOGUS\") threw an IllegalArgumentException");
    }
    Locale[] avail = Currency.getAvailableLocales();
    if (avail == null) {
        errln("FAIL: getAvailableLocales returned null");
    }
    try {
        usd.getName(ULocale.US, 5, new boolean[1]);
        errln("expected getName with invalid type parameter to throw exception");
    } catch (Exception e) {
        logln("PASS: getName failed as expected");
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) Currency(android.icu.util.Currency) Test(org.junit.Test)

Example 24 with Currency

use of android.icu.util.Currency in project j2objc by google.

the class CurrencyTest method testGetRoundingIncrement.

@Test
public void testGetRoundingIncrement() {
    Currency currency = Currency.getInstance(ULocale.JAPAN);
    // It appears as though this always returns 0 irrespective of the currency.
    double roundingIncrement = currency.getRoundingIncrement();
    assertEquals("Rounding increment not zero", 0.0, roundingIncrement, 0.0);
}
Also used : Currency(android.icu.util.Currency) Test(org.junit.Test)

Example 25 with Currency

use of android.icu.util.Currency in project j2objc by google.

the class CurrencyTest method TestCoverage.

@Test
public void TestCoverage() {
    Currency usd = Currency.getInstance("USD");
    assertEquals("USD.getSymbol()", "$", usd.getSymbol());
}
Also used : Currency(android.icu.util.Currency) Test(org.junit.Test)

Aggregations

Currency (android.icu.util.Currency)28 Test (org.junit.Test)19 ULocale (android.icu.util.ULocale)13 Locale (java.util.Locale)7 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)4 NumberFormat (android.icu.text.NumberFormat)4 RuleBasedNumberFormat (android.icu.text.RuleBasedNumberFormat)4 CurrencyAmount (android.icu.util.CurrencyAmount)4 CompactDecimalFormat (android.icu.text.CompactDecimalFormat)3 DecimalFormat (android.icu.text.DecimalFormat)3 AttributedString (java.text.AttributedString)3 StandardPlural (android.icu.impl.StandardPlural)2 MeasureUnit (android.icu.util.MeasureUnit)2 BigDecimal (android.icu.math.BigDecimal)1 MeasureFormat (android.icu.text.MeasureFormat)1 GlobalizationPreferences (android.icu.util.GlobalizationPreferences)1 Output (android.icu.util.Output)1 ParseException (java.text.ParseException)1 ParsePosition (java.text.ParsePosition)1