### Question:
PaymentUtils { static String formatPriceString(double amount, @NonNull Currency currency) { double majorUnitAmount = amount / Math.pow(10, currency.getDefaultFractionDigits()); NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) currencyFormat).getDecimalFormatSymbols(); decimalFormatSymbols.setCurrencySymbol(currency.getSymbol(Locale.getDefault())); ((java.text.DecimalFormat) currencyFormat).setDecimalFormatSymbols(decimalFormatSymbols); return currencyFormat.format(majorUnitAmount); }    }### Answer:
@Test public void formatPriceString_whenUSLocale_rendersCorrectSymbols() { Locale.setDefault(Locale.US); assertEquals(PaymentUtils.formatPriceString(12300, Currency.getInstance("USD")), "$123.00"); Currency euro = Currency.getInstance(Locale.GERMANY); assertEquals(PaymentUtils.formatPriceString(12300, euro), "EUR123.00"); Currency canadianDollar = Currency.getInstance(Locale.CANADA); assertEquals(PaymentUtils.formatPriceString(12300, canadianDollar), "CAD123.00"); Currency britishPound = Currency.getInstance(Locale.UK); assertEquals(PaymentUtils.formatPriceString(10000, britishPound), "GBP100.00"); }
@Test public void formatPriceString_whenInternationalLocale_rendersCorrectSymbols() { Locale.setDefault(Locale.GERMANY); Currency euro = Currency.getInstance(Locale.GERMANY); assertEquals(PaymentUtils.formatPriceString(10000, euro), "100,00 €"); Locale.setDefault(Locale.JAPAN); Currency yen = Currency.getInstance(Locale.JAPAN); assertEquals(PaymentUtils.formatPriceString(100, yen), "￥100"); Locale.setDefault(new Locale("ar", "JO")); Currency jordanianDinar = Currency.getInstance("JOD"); assertEquals(PaymentUtils.formatPriceString(100123, jordanianDinar), jordanianDinar.getSymbol() + " 100.123"); Locale.setDefault(Locale.UK); Currency britishPound = Currency.getInstance(Locale.UK); assertEquals(PaymentUtils.formatPriceString(10000, britishPound), "£100.00"); Locale.setDefault(Locale.CANADA); Currency canadianDollar = Currency.getInstance(Locale.CANADA); assertEquals(PaymentUtils.formatPriceString(12300, canadianDollar), "$123.00"); }
@Test public void formatPriceString_whenDecimalAmounts_rendersCorrectDigits() { assertEquals(PaymentUtils.formatPriceString(10012, Currency.getInstance("USD")), "$100.12"); assertEquals(PaymentUtils.formatPriceString(12, Currency.getInstance("USD")), "$0.12"); }