26
26
* @bug 4691089 4819436 4942982 5104960 6544471 6627549 7066203 7195759
27
27
* 8039317 8074350 8074351 8145952 8187946 8193552 8202026 8204269
28
28
* 8208746 8209775 8264792 8274658 8283277 8296239 8321480 8334653
29
- * 8354344
29
+ * 8354343 8354344
30
30
* @summary Validate ISO 4217 data for Currency class.
31
31
* @modules java.base/java.util:open
32
32
* jdk.localedata
71
71
import java .util .Set ;
72
72
import java .util .StringTokenizer ;
73
73
import java .util .TimeZone ;
74
+ import java .util .stream .Collectors ;
74
75
import java .util .stream .Stream ;
75
76
76
77
import org .junit .jupiter .api .BeforeAll ;
@@ -111,6 +112,8 @@ public class ValidateISO4217 {
111
112
private static final List <Arguments > additionalCodes = new ArrayList <Arguments >();
112
113
// Currencies to test (derived from ISO4217Codes and additionalCodes)
113
114
private static final Set <Currency > testCurrencies = new HashSet <>();
115
+ // Special case currencies that should only exist after the cut-over occurs
116
+ private static final Set <String > currenciesNotYetDefined = new HashSet <>();
114
117
// Codes that are obsolete, do not have related country, extra currency
115
118
private static final String otherCodes =
116
119
"ADP-AFA-ATS-AYM-AZM-BEF-BGL-BOV-BYB-BYR-CHE-CHW-CLF-COU-CUC-CYP-"
@@ -235,13 +238,14 @@ private static void patchClass(String name) throws IOException {
235
238
}
236
239
237
240
// Sets up the following test data:
238
- // ISO4217Codes, additionalCodes, testCurrencies, codes
241
+ // ISO4217Codes, additionalCodes, testCurrencies, codes, currenciesNotYetDefined
239
242
static void setUpTestingData () throws Exception {
240
243
// These functions laterally setup 'testCurrencies' and 'codes'
241
244
// at the same time
242
245
setUpISO4217Codes ();
243
246
setUpAdditionalCodes ();
244
247
setUpOtherCurrencies ();
248
+ setUpNotYetDefined ();
245
249
}
246
250
247
251
// Parse the ISO4217 file and populate ISO4217Codes and testCurrencies.
@@ -294,6 +298,11 @@ private static void processColumns(StringTokenizer tokens, String country) throw
294
298
numeric = tokens .nextToken ();
295
299
minorUnit = tokens .nextToken ();
296
300
testCurrencies .add (Currency .getInstance (currency ));
301
+ } else {
302
+ // Add all future currencies to the set.
303
+ // We process it later once 'testCurrencies' is complete
304
+ // to only include ones that should not be defined yet.
305
+ currenciesNotYetDefined .add (tokens .nextToken ());
297
306
}
298
307
}
299
308
}
@@ -339,6 +348,17 @@ private static void setUpOtherCurrencies() {
339
348
}
340
349
}
341
350
351
+ // Future currencies that are already defined as ISO 4217 codes should be
352
+ // removed. For example, in CW=ANG;2025-04-01-04-00-00;EUR "EUR" would be
353
+ // removed as it is an already valid ISO 4217 code
354
+ private static void setUpNotYetDefined () {
355
+ var allFutureCurrencies = testCurrencies
356
+ .stream ()
357
+ .map (Currency ::getCurrencyCode )
358
+ .collect (Collectors .toSet ());
359
+ currenciesNotYetDefined .removeIf (allFutureCurrencies ::contains );
360
+ }
361
+
342
362
// Check that the data file is up-to-date
343
363
@ Test
344
364
public void dataVersionTest () {
@@ -419,6 +439,18 @@ private static List<String> codeCombos() {
419
439
return codeCombos ;
420
440
}
421
441
442
+ // Any future currencies that do not already exist before the cut-over
443
+ // should not be instantiable. This scenario is when a country transfers
444
+ // to a new code, that is not already a valid ISO 4217 code. For example,
445
+ // what occurred in the 176 update situation.
446
+ @ Test
447
+ public void nonDefinedFutureCurrenciesTest () {
448
+ for (String curr : currenciesNotYetDefined ) {
449
+ assertThrows (IllegalArgumentException .class , () -> Currency .getInstance (curr ),
450
+ "The future cut-over currency: %s should not exist" .formatted (curr ));
451
+ }
452
+ }
453
+
422
454
// This method ensures that getAvailableCurrencies() returns
423
455
// the expected amount of currencies.
424
456
@ Test
@@ -427,6 +459,8 @@ public void getAvailableCurrenciesTest() {
427
459
// Ensure that testCurrencies has all the JRE currency codes
428
460
assertTrue (testCurrencies .containsAll (jreCurrencies ),
429
461
getSetDiffs (jreCurrencies , testCurrencies ));
462
+ // Implicitly checks that jreCurrencies does not contain any currencies
463
+ // defined in currenciesNotYetDefined
430
464
}
431
465
432
466
private static String getSetDiffs (Set <Currency > jreCurrencies , Set <Currency > testCurrencies ) {
0 commit comments