/* * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ /* * @test * @bug 4290801 4692419 4693631 5101540 5104960 6296410 6336600 6371531 * 6488442 7036905 8008577 8039317 8074350 8074351 8150324 8167143 * 8264792 * @summary Basic tests for Currency class. * @modules java.base/java.util:open * jdk.localedata
*/
staticvoid testLocaleMapping() { // very basic test: most countries have their own currency, and then // their currency code is an extension of their country code.
Locale[] locales = Locale.getAvailableLocales(); int goodCountries = 0; int ownCurrencies = 0; for (int i = 0; i < locales.length; i++) {
Locale locale = locales[i];
String ctryCode = locale.getCountry(); int ctryLength = ctryCode.length(); if (ctryLength == 0 ||
ctryLength == 3 || // UN M.49 code
ctryCode.matches("AA|Q[M-Z]|X[A-JL-Z]|ZZ" + // user defined codes, excluding "XK" (Kosovo) "AC|CP|DG|EA|EU|FX|IC|SU|TA|UK")) { // exceptional reservation codes boolean gotException = false; try {
Currency.getInstance(locale);
} catch (IllegalArgumentException e) {
gotException = true;
} if (!gotException) { thrownew RuntimeException("didn't get specified exception");
}
} else {
goodCountries++;
Currency currency = Currency.getInstance(locale); if (currency.getCurrencyCode().indexOf(locale.getCountry()) == 0) {
ownCurrencies++;
}
}
}
System.out.println("Countries tested: " + goodCountries + ", own currencies: " + ownCurrencies); if (ownCurrencies < (goodCountries / 2 + 1)) { thrownew RuntimeException("suspicious: not enough countries have their own currency.");
}
// check a few countries that don't change their currencies too often
String[] country1 = {"US", "CA", "JP", "CN", "SG", "CH"};
String[] currency1 = {"USD", "CAD", "JPY", "CNY", "SGD", "CHF"}; for (int i = 0; i < country1.length; i++) {
checkCountryCurrency(country1[i], currency1[i]);
}
/* * check currency changes * In current implementation, there is no data of old currency and transition date at jdk/src/java.base/share/data/currency/CurrencyData.properties. * So, all the switch data arrays are empty. In the future, if data of old currency and transition date are necessary for any country, the * arrays here can be updated so that the program can check the currency switch.
*/
String[] switchOverCtry = {};
String[] switchOverOld = {};
String[] switchOverNew = {};
String[] switchOverTZ = {}; int[] switchOverYear = {}; int[] switchOverMonth = {}; // java.time APIs accept month starting from 1 i.e. 01 for January int[] switchOverDay = {};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.