From 4bb8a5fe2145a37f51da67a797d849cf8bcb81d5 Mon Sep 17 00:00:00 2001 From: Kieran Farrell Date: Sun, 6 Apr 2025 22:30:32 +0100 Subject: [PATCH] currency updates --- .../share/classes/java/util/Currency.java | 16 ++++++++-------- test/jdk/java/util/Currency/CurrencyTest.java | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/java.base/share/classes/java/util/Currency.java b/src/java.base/share/classes/java/util/Currency.java index 789eefad5d5..25465cab8be 100644 --- a/src/java.base/share/classes/java/util/Currency.java +++ b/src/java.base/share/classes/java/util/Currency.java @@ -311,8 +311,8 @@ private static Currency getInstance(String currencyCode, int defaultFractionDigi // or in the list of other currencies. boolean found = false; if (currencyCode.length() != 3) { - throw new IllegalArgumentException("The input currency code must " + - "have a length of 3 characters"); + throw new IllegalArgumentException("The input currency code '" + currencyCode + + "' must have a length of 3 characters"); } char char1 = currencyCode.charAt(0); char char2 = currencyCode.charAt(1); @@ -335,8 +335,8 @@ private static Currency getInstance(String currencyCode, int defaultFractionDigi if (!found) { OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode); if (ocEntry == null) { - throw new IllegalArgumentException("The input currency code" + - " is not a valid ISO 4217 code"); + throw new IllegalArgumentException("The input currency code'" + currencyCode + + "' is not a valid ISO 4217 code"); } defaultFractionDigits = ocEntry.fraction; numericCode = ocEntry.numericCode; @@ -391,8 +391,8 @@ public static Currency getInstance(Locale locale) { String country = CalendarDataUtility.findRegionOverride(locale).getCountry(); if (country == null || !country.matches("^[a-zA-Z]{2}$")) { - throw new IllegalArgumentException("The country of the input locale" + - " is not a valid ISO 3166 country code"); + throw new IllegalArgumentException("The country of the input locale '" + locale + + "' is not a valid ISO 3166 country code"); } char char1 = country.charAt(0); @@ -409,8 +409,8 @@ public static Currency getInstance(Locale locale) { } else { // special cases if (tableEntry == INVALID_COUNTRY_ENTRY) { - throw new IllegalArgumentException("The country of the input locale" + - " is not a valid ISO 3166 country code"); + throw new IllegalArgumentException("The country of the input locale '" + locale + + "' is not a valid ISO 3166 country code"); } if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) { return null; diff --git a/test/jdk/java/util/Currency/CurrencyTest.java b/test/jdk/java/util/Currency/CurrencyTest.java index c8dfb5013bd..17a2e76ee57 100644 --- a/test/jdk/java/util/Currency/CurrencyTest.java +++ b/test/jdk/java/util/Currency/CurrencyTest.java @@ -84,8 +84,8 @@ private static Stream validCurrencies() { public void invalidCurrencyTest(String currencyCode) { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> Currency.getInstance(currencyCode), "getInstance() did not throw IAE"); - assertEquals("The input currency code is not a" + - " valid ISO 4217 code", ex.getMessage()); + assertEquals("The input currency code'" + currencyCode + + "' is not a valid ISO 4217 code", ex.getMessage()); } private static Stream non4217Currencies() { @@ -99,8 +99,8 @@ private static Stream non4217Currencies() { public void invalidCurrencyLengthTest(String currencyCode) { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> Currency.getInstance(currencyCode), "getInstance() did not throw IAE"); - assertEquals("The input currency code must have a length of 3" + - " characters", ex.getMessage()); + assertEquals("The input currency code '" + currencyCode + + "' must have a length of 3 characters", ex.getMessage()); } private static Stream invalidLengthCurrencies() { @@ -163,8 +163,8 @@ public void localeMappingTest() { "AC|CP|DG|EA|EU|FX|IC|SU|TA|UK")) { // exceptional reservation codes IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> Currency.getInstance(locale), "Did not throw IAE"); - assertEquals("The country of the input locale is not a" + - " valid ISO 3166 country code", ex.getMessage()); + assertEquals("The country of the input locale '" + locale + "' is not a " + + "valid ISO 3166 country code", ex.getMessage()); } else { goodCountries++; Currency currency = Currency.getInstance(locale); @@ -183,10 +183,11 @@ public void localeMappingTest() { // Check an invalid country code @Test public void invalidCountryTest() { + Locale locale = Locale.of("", "EU"); IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, ()-> Currency.getInstance(Locale.of("", "EU")), "Did not throw IAE"); - assertEquals("The country of the input locale is not a valid" + - " ISO 3166 country code", ex.getMessage()); + assertEquals("The country of the input locale '" + locale + + "' is not a valid ISO 3166 country code", ex.getMessage()); } // Ensure a selection of countries have the expected currency