/** @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()); }
/** 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; }