Search in sources :

Example 41 with Currency

use of java.util.Currency in project j2objc by google.

the class CurrencyTest method testSerialization.

public void testSerialization() throws Exception {
    Currency usd = Currency.getInstance("USD");
    String actual = SerializationTester.serializeHex(usd);
    String expected = "aced0005737200126a6176612e7574696c2e43757272656e6379fdcd934a5911a91f02" + "00014c000c63757272656e6379436f64657400124c6a6176612f6c616e672f537472696e673b7870" + "740003555344";
    assertEquals(expected, actual);
    Currency deserializedUsd = (Currency) SerializationTester.deserializeHex(expected);
    assertSame("Currency objects should be singletons", usd, deserializedUsd);
}
Also used : Currency(java.util.Currency)

Example 42 with Currency

use of java.util.Currency in project j2objc by google.

the class CurrencyTest method test_nullLocales.

public void test_nullLocales() {
    Currency currency = Currency.getInstance(Locale.getDefault());
    try {
        currency.getSymbol(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : Currency(java.util.Currency)

Example 43 with Currency

use of java.util.Currency in project j2objc by google.

the class DecimalFormatSymbolsTest method test_setInternationalCurrencySymbolLjava_lang_String.

/**
     * @tests java.text.DecimalFormatSymbols#setInternationalCurrencySymbol(java.lang.String)
     */
public void test_setInternationalCurrencySymbolLjava_lang_String() {
    Locale locale = Locale.CANADA;
    DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).getDecimalFormatSymbols();
    Currency currency = Currency.getInstance("JPY");
    dfs.setInternationalCurrencySymbol(currency.getCurrencyCode());
    assertTrue("Test1: Returned incorrect currency", currency == dfs.getCurrency());
    assertEquals("Test1: Returned incorrect currency symbol", currency.getSymbol(locale), dfs.getCurrencySymbol());
    assertTrue("Test1: Returned incorrect international currency symbol", currency.getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));
    dfs.setInternationalCurrencySymbol("bogus");
    // RI support this legacy country code
    // assertNotNull("Test2: Returned incorrect currency", dfs.getCurrency());
    assertEquals("Test2: Returned incorrect international currency symbol", "bogus", dfs.getInternationalCurrencySymbol());
}
Also used : Locale(java.util.Locale) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) Currency(java.util.Currency)

Example 44 with Currency

use of java.util.Currency in project j2objc by google.

the class DecimalFormatSymbolsTest method test_setCurrencyLjava_util_Currency.

/**
     * @tests java.text.DecimalFormatSymbols#setCurrency(java.util.Currency)
     */
public void test_setCurrencyLjava_util_Currency() {
    Locale locale = Locale.CANADA;
    DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).getDecimalFormatSymbols();
    try {
        dfs.setCurrency(null);
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    }
    Currency currency = Currency.getInstance("JPY");
    dfs.setCurrency(currency);
    assertTrue("Returned incorrect currency", currency == dfs.getCurrency());
    assertEquals("Returned incorrect currency symbol", currency.getSymbol(locale), dfs.getCurrencySymbol());
    assertTrue("Returned incorrect international currency symbol", currency.getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));
}
Also used : Locale(java.util.Locale) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) Currency(java.util.Currency)

Example 45 with Currency

use of java.util.Currency in project j2objc by google.

the class DecimalFormatSymbolsTest method test_serialization.

// Test serialization mechanism of DecimalFormatSymbols
public void test_serialization() throws Exception {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRANCE);
    Currency currency = symbols.getCurrency();
    assertNotNull(currency);
    // serialize
    ByteArrayOutputStream byteOStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream);
    objectOStream.writeObject(symbols);
    // and deserialize
    ObjectInputStream objectIStream = new ObjectInputStream(new ByteArrayInputStream(byteOStream.toByteArray()));
    DecimalFormatSymbols symbolsD = (DecimalFormatSymbols) objectIStream.readObject();
    // The associated currency will not persist
    currency = symbolsD.getCurrency();
    assertNotNull(currency);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ByteArrayInputStream(java.io.ByteArrayInputStream) Currency(java.util.Currency) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Currency (java.util.Currency)60 Locale (java.util.Locale)21 BigDecimal (java.math.BigDecimal)8 NumberFormat (java.text.NumberFormat)8 DecimalFormat (java.text.DecimalFormat)7 DecimalFormatSymbols (java.text.DecimalFormatSymbols)7 ChoiceFormat (java.text.ChoiceFormat)3 HashSet (java.util.HashSet)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 ParsePosition (java.text.ParsePosition)2 ArrayList (java.util.ArrayList)2 Exchange (org.apache.camel.Exchange)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ImmutableSet (com.google.common.collect.ImmutableSet)1