Skip to content

Commit

Permalink
Merge pull request #969 from /issues/968-monetary-converter
Browse files Browse the repository at this point in the history
Fix #968: MonetaryConverter throws an exception for currency '...'
  • Loading branch information
banterCZ authored Dec 21, 2023
2 parents 3a54da3 + dd7cf0a commit c460f13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import javax.money.CurrencyUnit;
import javax.money.Monetary;
import javax.money.UnknownCurrencyException;
import javax.money.MonetaryException;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Currency;
Expand Down Expand Up @@ -113,7 +113,7 @@ private static int getFractionDigits(String code) {
try {
final CurrencyUnit currencyUnit = Monetary.getCurrency(code);
return currencyUnit.getDefaultFractionDigits();
} catch (UnknownCurrencyException e) {
} catch (MonetaryException e) {
logger.debug("No currency mapping for code={}, most probably not FIAT", code);
logger.trace("No currency mapping for code={}", code, e);
return DEFAULT_MINIMAL_FRACTION_DIGITS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class MonetaryConverterTest {
"NZD, en, NZ$",
"NZD, cs, NZ$",
"NZD, nz, NZ$",
"BTC, cs, BTC"
"BTC, cs, BTC",
"..., cs, ..."
})
void testFormatCurrency(final String source, final String locale, final String expected) {
final String result = MonetaryConverter.formatCurrency(source, new Locale(locale));
Expand All @@ -68,7 +69,8 @@ void testFormatCurrency(final String source, final String locale, final String e
"1, BTC, en, '1'",
"1.1, BTC, en, '1.1'",
"0.123456789, BTC, en, '0.123456789'",
"0.567567567567567567567, BTC, en, '0.567567567567567567'"
"0.567567567567567567567, BTC, en, '0.567567567567567567'",
"1, ..., en, '1'"
})
void testFormatAmount(final String amount, final String code, final String locale, final String expected) {
final String result = MonetaryConverter.formatAmount(new BigDecimal(amount), code, new Locale(locale));
Expand All @@ -92,7 +94,8 @@ void testFormatAmount(final String amount, final String code, final String local
"1, BTC, en, '1 BTC'",
"1.1, BTC, en, '1.1 BTC'",
"0.123456789, BTC, en, '0.123456789 BTC'",
"0.567567567567567567567, BTC, en, '0.567567567567567567 BTC'"
"0.567567567567567567567, BTC, en, '0.567567567567567567 BTC'",
"1, ..., en, '1 ...'"
})
void testFormatValue(final String amount, final String code, final String locale, final String expected) {
final String result = MonetaryConverter.formatValue(new BigDecimal(amount), code, new Locale(locale));
Expand Down

0 comments on commit c460f13

Please sign in to comment.