/** @tests java.text.DecimalFormatSymbols#setInternationalCurrencySymbol(java.lang.String) */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "setInternationalCurrencySymbol", args = {java.lang.String.class}) @KnownFailure("getCurrency() doesn't return null for bogus currency code.") 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())); String symbol = dfs.getCurrencySymbol(); dfs.setInternationalCurrencySymbol("bogus"); assertNull("Test2: Returned incorrect currency", dfs.getCurrency()); assertTrue("Test2: Returned incorrect currency symbol", dfs.getCurrencySymbol().equals(symbol)); assertEquals( "Test2: Returned incorrect international currency symbol", "bogus", dfs.getInternationalCurrencySymbol()); }
static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) { // Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE /* * currency = [EUR] * currencySymbol = [€][U+20ac] * decimalSeparator = [,][U+002c] * digit = [#][U+0023] * groupingSeparator = [ ][U+00a0] * infinity = [∞][U+221e] * internationalCurrencySymbol = [EUR] * minusSign = [-][U+002d] * monetaryDecimalSeparator = [,][U+002c] * naN = [�][U+fffd] * patternSeparator = [;][U+003b] * perMill = [‰][U+2030] * percent = [%][U+0025] * zeroDigit = [0][U+0030] */ assertEquals("EUR", dfs.getCurrency().getCurrencyCode()); assertEquals("\u20AC", dfs.getCurrencySymbol()); assertEquals(',', dfs.getDecimalSeparator()); assertEquals('#', dfs.getDigit()); assertEquals('\u00a0', dfs.getGroupingSeparator()); assertEquals("\u221e", dfs.getInfinity()); assertEquals("EUR", dfs.getInternationalCurrencySymbol()); assertEquals('-', dfs.getMinusSign()); assertEquals(',', dfs.getMonetaryDecimalSeparator()); // RI's default NaN is U+FFFD, Harmony's is based on ICU assertEquals("\uFFFD", dfs.getNaN()); assertEquals('\u003b', dfs.getPatternSeparator()); assertEquals('\u2030', dfs.getPerMill()); assertEquals('%', dfs.getPercent()); assertEquals('0', dfs.getZeroDigit()); }
private static void describeDecimalFormatSymbols(StringBuilder result, DecimalFormatSymbols dfs) { result.append("Currency Symbol: " + unicodeString(dfs.getCurrencySymbol()) + "\n"); result.append( "International Currency Symbol: " + unicodeString(dfs.getInternationalCurrencySymbol()) + "\n"); result.append("<p>"); result.append("Digit: " + unicodeString(dfs.getDigit()) + "\n"); result.append("Pattern Separator: " + unicodeString(dfs.getPatternSeparator()) + "\n"); result.append("<p>"); result.append("Decimal Separator: " + unicodeString(dfs.getDecimalSeparator()) + "\n"); result.append( "Monetary Decimal Separator: " + unicodeString(dfs.getMonetaryDecimalSeparator()) + "\n"); // 1.6: result.append("Exponent Separator: " + dfs.getExponentSeparator() + "\n"); result.append("Grouping Separator: " + unicodeString(dfs.getGroupingSeparator()) + "\n"); result.append("Infinity: " + unicodeString(dfs.getInfinity()) + "\n"); result.append("Minus Sign: " + unicodeString(dfs.getMinusSign()) + "\n"); result.append("NaN: " + unicodeString(dfs.getNaN()) + "\n"); result.append("Percent: " + unicodeString(dfs.getPercent()) + "\n"); result.append("Per Mille: " + unicodeString(dfs.getPerMill()) + "\n"); result.append("Zero Digit: " + unicodeString(dfs.getZeroDigit()) + "\n"); StringBuilder digits = new StringBuilder(); for (int i = 0; i <= 9; ++i) { digits.append((char) (dfs.getZeroDigit() + i)); } result.append("Digits: " + digits.toString() + "\n"); result.append("<p>"); result.append("<p>"); }
/** @tests java.text.DecimalFormatSymbols#setCurrency(java.util.Currency) */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "setCurrency", args = {java.util.Currency.class}) 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())); }
/** @tests java.text.DecimalFormatSymbols#getCurrencySymbol() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getCurrencySymbol", args = {}) public void test_getCurrencySymbol() { assertEquals("Returned incorrect currencySymbol", "$", dfsUS.getCurrencySymbol()); }
public static void main(String[] args) { try { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); System.out.println( "Default currency symbol in the default locale : " + dfs.getCurrencySymbol()); dfs.setCurrencySymbol("*SpecialCurrencySymbol*"); System.out.println("The special currency symbol is set : " + dfs.getCurrencySymbol()); FileOutputStream ostream = new FileOutputStream("DecimalFormatSymbols.142"); ObjectOutputStream p = new ObjectOutputStream(ostream); p.writeObject(dfs); ostream.close(); System.out.println("DecimalFormatSymbols saved ok."); } catch (Exception e) { e.printStackTrace(); } }
/** * @tests java.text.DecimalFormatSymbols#setCurrencySymbol(java.lang.String) Test of method * java.text.DecimalFormatSymbols#setCurrencySymbol(java.lang.String). */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "setCurrencySymbol", args = {java.lang.String.class}) public void test_setCurrencySymbolLjava_lang_String() { try { dfs.setCurrencySymbol("$"); assertEquals("Returned incorrect CurrencySymbol symbol", "$", dfs.getCurrencySymbol()); } catch (Exception e) { fail("Unexpected exception " + e.toString()); } }
/** Adjusts {@link DecimalFormat}'s symbol according to given {@link CurrencyModel}. */ protected DecimalFormat adjustSymbol( final DecimalFormat format, final CurrencyModel currencyModel) { final String symbol = currencyModel.getSymbol(); if (symbol != null) { final DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); // does cloning final String iso = currencyModel.getIsocode(); boolean changed = false; if (!iso.equalsIgnoreCase(symbols.getInternationalCurrencySymbol())) { symbols.setInternationalCurrencySymbol(iso); changed = true; } if (!symbol.equals(symbols.getCurrencySymbol())) { symbols.setCurrencySymbol(symbol); changed = true; } if (changed) { format.setDecimalFormatSymbols(symbols); } } return format; }
/** @tests java.text.DecimalFormatSymbols#getCurrency() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getCurrency", args = {}) public void test_getCurrency() { Locale csCzLocale = new Locale("cs", "CZ"); Locale czLocale = new Locale("", "CZ"); Locale csLocale = new Locale("cs", ""); Locale deLocale = new Locale("de", "AT"); Locale[] requiredLocales = {Locale.US, csCzLocale, czLocale, csLocale, deLocale}; if (!Support_Locale.areLocalesAvailable(requiredLocales)) { // locale dependent test, bug 1943269 return; } Currency currency = Currency.getInstance("USD"); assertEquals("Returned incorrect currency", dfsUS.getCurrency(), currency); // use cs_CZ instead // Currency currK = Currency.getInstance("KRW"); Currency currC = Currency.getInstance("CZK"); Currency currX = Currency.getInstance("XXX"); Currency currE = Currency.getInstance("EUR"); // Currency currF = Currency.getInstance("FRF"); DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(csCzLocale); assertTrue("Test1: Returned incorrect currency", dfs1.getCurrency() == currC); assertEquals("Test1: Returned incorrect currencySymbol", "K\u010d", dfs1.getCurrencySymbol()); assertEquals( "Test1: Returned incorrect intlCurrencySymbol", "CZK", dfs1.getInternationalCurrencySymbol()); dfs1 = new DecimalFormatSymbols(czLocale); assertTrue("Test2: Returned incorrect currency", dfs1.getCurrency() == currC); assertEquals("Test2: Returned incorrect currencySymbol", "CZK", dfs1.getCurrencySymbol()); assertEquals( "Test2: Returned incorrect intlCurrencySymbol", "CZK", dfs1.getInternationalCurrencySymbol()); dfs1 = new DecimalFormatSymbols(csLocale); assertEquals("Test3: Returned incorrect currency", currX, dfs1.getCurrency()); assertEquals("Test3: Returned incorrect currencySymbol", "\u00a4", dfs1.getCurrencySymbol()); assertEquals( "Test3: Returned incorrect intlCurrencySymbol", "XXX", dfs1.getInternationalCurrencySymbol()); dfs1 = new DecimalFormatSymbols(deLocale); assertTrue("Test4: Returned incorrect currency", dfs1.getCurrency() == currE); assertEquals("Test4: Returned incorrect currencySymbol", "\u20ac", dfs1.getCurrencySymbol()); assertEquals( "Test4: Returned incorrect intlCurrencySymbol", "EUR", dfs1.getInternationalCurrencySymbol()); // RI fails these tests since it doesn't have the PREEURO variant // dfs1 = new DecimalFormatSymbols(new Locale("fr", "FR","PREEURO")); // assertTrue("Test5: Returned incorrect currency", dfs1.getCurrency() // == currF); // assertTrue("Test5: Returned incorrect currencySymbol", // dfs1.getCurrencySymbol().equals("F")); // assertTrue("Test5: Returned incorrect intlCurrencySymbol", // dfs1.getInternationalCurrencySymbol().equals("FRF")); }
public static String getCurrencySymbol(NumberFormat formatter) { DecimalFormatSymbols symbols = ((DecimalFormat) formatter).getDecimalFormatSymbols(); return symbols.getCurrencySymbol(); }