/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
* @summary Basic tests for Currency class.
*/
public class CurrencyTest {
testSymbols();
}
static void testCurrencyCodeValidation() {
// test creation of some valid currencies
testValidCurrency("USD");
testValidCurrency("EUR");
testValidCurrency("GBP");
testValidCurrency("JPY");
testValidCurrency("CNY");
testValidCurrency("CHF");
// test creation of some fictitious currencies
testInvalidCurrency("AQD");
testInvalidCurrency("US$");
testInvalidCurrency("\u20AC");
}
throw new RuntimeException("Didn't get same instance for same currency code");
}
throw new RuntimeException("Currency code changed");
}
}
boolean gotException = false;
try {
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
throw new RuntimeException("didn't get specified exception");
}
}
static void testLocaleMapping() {
// very basic test: most countries have their own currency, and then
// their currency code is an extension of their country code.
int goodCountries = 0;
int ownCurrencies = 0;
boolean gotException = false;
try {
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
throw new RuntimeException("didn't get specified exception");
}
} else {
}
}
}
", own currencies: " + ownCurrencies);
throw new RuntimeException("suspicious: not enough countries have their own currency.");
}
// check a few countries that don't change their currencies too often
}
// check currency changes
String[] switchOverOld = {"DEM", "FRF", "ESP", "ITL", "NLG", "BEF", "TRL", "ROL", "AZM", "MZM", "GHC", "VEB"};
String[] switchOverNew = {"EUR", "EUR", "EUR", "EUR", "EUR", "EUR", "TRY", "RON", "AZN", "MZN", "GHS", "VEF"};
}
// check a country code which doesn't have a currency
// check an invalid country code
boolean gotException = false;
try {
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
throw new RuntimeException("didn't get specified exception.");
}
}
throw new RuntimeException("Wrong currency for " +
}
}
static void testSymbols() {
}
throw new RuntimeException("Wrong symbol for currency " +
", got " + symbol);
}
}
static void testFractionDigits() {
// Turkish Lira
}
if (digits != expectedFractionDigits) {
throw new RuntimeException("Wrong number of fraction digits for currency " +
", got " + digits);
}
}
throw new RuntimeException("serialization breaks class invariant");
}
}
static void testDisplayNames() {
// null argument test
try {
throw new RuntimeException("getDisplayName(NULL) did not throw an NPE.");
} catch (NullPointerException npe) {}
}
throw new RuntimeException("Wrong display name for currency " +
}
}
}