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);
}
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) {
}
}
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());
}
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()));
}
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);
}
Aggregations