return;
}
+ // Ensure that we throw if the our currency code isn't an ISO currency code.
+ String symbol = Resources.getCurrencySymbolNative(Locale.US.toString(), currencyCode);
+ if (symbol == null) {
+ throw new IllegalArgumentException(Msg.getString("K0322", currencyCode));
+ }
+
this.defaultFractionDigits = Resources.getCurrencyFractionDigitsNative(currencyCode);
if (defaultFractionDigits < 0) {
+ // In practice, I don't think this can fail because ICU doesn't care whether you give
+ // it a valid country code, and will just return a sensible default for the default
+ // locale's currency.
throw new IllegalArgumentException(Msg.getString("K0322", currencyCode));
}
// END android-changed
// Canada that Canadians give it a localized (to Canada) symbol.
assertEquals("AED", Currency.getInstance("AED").getSymbol(Locale.CANADA));
}
+
+ // Regression test to ensure that Currency.getInstance(String) throws if
+ // given an invalid ISO currency code.
+ public void test_getInstance_illegal_currency_code() throws Exception {
+ Currency.getInstance("USD");
+ try {
+ Currency.getInstance("BOGO-DOLLARS");
+ fail("expected IllegalArgumentException for invalid ISO currency code");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
}