2 **********************************************************************
3 * Copyright (c) 2002-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: December 18 2002
9 **********************************************************************
12 package com.ibm.icu.dev.test.util;
14 import java.util.Arrays;
15 import java.util.Date;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Locale;
21 import com.ibm.icu.dev.test.TestFmwk;
22 import com.ibm.icu.impl.CurrencyData;
23 import com.ibm.icu.text.CurrencyDisplayNames;
24 import com.ibm.icu.text.CurrencyMetaInfo;
25 import com.ibm.icu.text.CurrencyMetaInfo.CurrencyFilter;
26 import com.ibm.icu.text.CurrencyMetaInfo.CurrencyInfo;
27 import com.ibm.icu.text.DateFormat;
28 import com.ibm.icu.text.DecimalFormatSymbols;
29 import com.ibm.icu.text.SimpleDateFormat;
30 import com.ibm.icu.util.Currency;
31 import com.ibm.icu.util.GregorianCalendar;
32 import com.ibm.icu.util.TimeZone;
33 import com.ibm.icu.util.ULocale;
37 * @summary General test of Currency
39 public class CurrencyTest extends TestFmwk {
41 public static void main(String[] args) throws Exception {
42 new CurrencyTest().run(args);
48 public void TestAPI() {
49 Currency usd = Currency.getInstance("USD");
50 /*int hash = */usd.hashCode();
51 Currency jpy = Currency.getInstance("JPY");
52 if (usd.equals(jpy)) {
53 errln("FAIL: USD == JPY");
55 if (usd.equals("abc")) {
56 errln("FAIL: USD == (String)");
58 if (usd.equals(null)) {
59 errln("FAIL: USD == (null)");
61 if (!usd.equals(usd)) {
62 errln("FAIL: USD != USD");
66 Currency nullCurrency = Currency.getInstance((String)null);
67 errln("FAIL: Expected getInstance(null) to throw "
68 + "a NullPointerException, but returned " + nullCurrency);
69 } catch (NullPointerException npe) {
70 logln("PASS: getInstance(null) threw a NullPointerException");
74 Currency bogusCurrency = Currency.getInstance("BOGUS");
75 errln("FAIL: Expected getInstance(\"BOGUS\") to throw "
76 + "an IllegalArgumentException, but returned " + bogusCurrency);
77 } catch (IllegalArgumentException iae) {
78 logln("PASS: getInstance(\"BOGUS\") threw an IllegalArgumentException");
81 Locale[] avail = Currency.getAvailableLocales();
83 errln("FAIL: getAvailableLocales returned null");
87 usd.getName(ULocale.US, 5, new boolean[1]);
88 errln("expected getName with invalid type parameter to throw exception");
91 logln("PASS: getName failed as expected");
98 public void TestRegistration() {
99 final Currency jpy = Currency.getInstance("JPY");
100 final Currency usd = Currency.getInstance(Locale.US);
103 Currency.unregister(null); // should fail, coverage
104 errln("expected unregister of null to throw exception");
106 catch (Exception e) {
107 logln("PASS: unregister of null failed as expected");
110 if (Currency.unregister("")) { // coverage
111 errln("unregister before register erroneously succeeded");
114 ULocale fu_FU = new ULocale("fu_FU");
116 Object key1 = Currency.registerInstance(jpy, ULocale.US);
117 Object key2 = Currency.registerInstance(jpy, fu_FU);
119 Currency nus = Currency.getInstance(Locale.US);
120 if (!nus.equals(jpy)) {
121 errln("expected " + jpy + " but got: " + nus);
124 // converage, make sure default factory works
125 Currency nus1 = Currency.getInstance(Locale.JAPAN);
126 if (!nus1.equals(jpy)) {
127 errln("expected " + jpy + " but got: " + nus1);
130 ULocale[] locales = Currency.getAvailableULocales();
131 boolean found = false;
132 for (int i = 0; i < locales.length; ++i) {
133 if (locales[i].equals(fu_FU)) {
139 errln("did not find locale" + fu_FU + " in currency locales");
142 if (!Currency.unregister(key1)) {
143 errln("unable to unregister currency using key1");
145 if (!Currency.unregister(key2)) {
146 errln("unable to unregister currency using key2");
149 Currency nus2 = Currency.getInstance(Locale.US);
150 if (!nus2.equals(usd)) {
151 errln("expected " + usd + " but got: " + nus2);
154 locales = Currency.getAvailableULocales();
156 for (int i = 0; i < locales.length; ++i) {
157 if (locales[i].equals(fu_FU)) {
163 errln("found locale" + fu_FU + " in currency locales after unregister");
166 Locale[] locs = Currency.getAvailableLocales();
168 for (int i = 0; i < locs.length; ++i) {
169 if (locs[i].equals(fu_FU)) {
175 errln("found locale" + fu_FU + " in currency locales after unregister");
182 public void TestNames() {
183 // Do a basic check of getName()
184 // USD { "US$", "US Dollar" } // 04/04/1792-
185 ULocale en = ULocale.ENGLISH;
186 boolean[] isChoiceFormat = new boolean[1];
187 Currency usd = Currency.getInstance("USD");
188 // Warning: HARD-CODED LOCALE DATA in this test. If it fails, CHECK
189 // THE LOCALE DATA before diving into the code.
191 assertEquals("USD.getName(SYMBOL_NAME)",
193 usd.getName(en, Currency.SYMBOL_NAME, isChoiceFormat));
194 assertEquals("USD.getName(LONG_NAME)",
196 usd.getName(en, Currency.LONG_NAME, isChoiceFormat));
198 // TODO add more tests later
201 public void TestCoverage() {
202 Currency usd = Currency.getInstance("USD");
204 assertEquals("USD.getSymbol()",
210 // A real test of the CurrencyDisplayNames class.
211 public void TestCurrencyDisplayNames() {
212 if (!CurrencyDisplayNames.hasData()) {
213 errln("hasData() should return true.");
217 CurrencyDisplayNames cdn = CurrencyDisplayNames.getInstance(ULocale.GERMANY);
218 assertEquals("de_USD_name", "US-Dollar", cdn.getName("USD"));
219 assertEquals("de_USD_symbol", "$", cdn.getSymbol("USD"));
220 assertEquals("de_USD_plural_other", "US-Dollar", cdn.getPluralName("USD", "other"));
221 // unknown plural category, substitute "other"
222 assertEquals("de_USD_plural_foo", "US-Dollar", cdn.getPluralName("USD", "foo"));
224 cdn = CurrencyDisplayNames.getInstance(ULocale.forLanguageTag("en-US"));
225 assertEquals("en-US_USD_name", "US Dollar", cdn.getName("USD"));
226 assertEquals("en-US_USD_symbol", "$", cdn.getSymbol("USD"));
227 assertEquals("en-US_USD_plural_one", "US dollar", cdn.getPluralName("USD", "one"));
228 assertEquals("en-US_USD_plural_other", "US dollars", cdn.getPluralName("USD", "other"));
230 assertEquals("en-US_FOO_name", "FOO", cdn.getName("FOO"));
231 assertEquals("en-US_FOO_symbol", "FOO", cdn.getSymbol("FOO"));
232 assertEquals("en-US_FOO_plural_other", "FOO", cdn.getPluralName("FOO", "other"));
234 assertEquals("en-US bundle", "en", cdn.getULocale().toString());
236 cdn = CurrencyDisplayNames.getInstance(ULocale.forLanguageTag("zz-Gggg-YY"));
237 assertEquals("bundle from current locale", "en", cdn.getULocale().toString());
239 // with no substitute
240 cdn = CurrencyDisplayNames.getInstance(ULocale.GERMANY, true);
241 assertNotNull("have currency data for Germany", cdn);
243 // known currency, behavior unchanged
244 assertEquals("de_USD_name", "US-Dollar", cdn.getName("USD"));
245 assertEquals("de_USD_symbol", "$", cdn.getSymbol("USD"));
246 assertEquals("de_USD_plural_other", "US-Dollar", cdn.getPluralName("USD", "other"));
248 // known currency but unknown plural category
249 assertNull("de_USD_plural_foo", cdn.getPluralName("USD", "foo"));
251 // unknown currency, get null
252 assertNull("de_FOO_name", cdn.getName("FOO"));
253 assertNull("de_FOO_symbol", cdn.getSymbol("FOO"));
254 assertNull("de_FOO_plural_other", cdn.getPluralName("FOO", "other"));
255 assertNull("de_FOO_plural_foo", cdn.getPluralName("FOO", "foo"));
257 // unknown locale with no substitute
258 cdn = CurrencyDisplayNames.getInstance(ULocale.forLanguageTag("zz-Gggg-YY"), true);
261 ln = " (" + cdn.getULocale().toString() + ")";
263 assertNull("no fallback from unknown locale" + ln , cdn);
266 // Coverage-only test of CurrencyData
267 public void TestCurrencyData() {
268 CurrencyData.DefaultInfo info_fallback = (CurrencyData.DefaultInfo)CurrencyData.DefaultInfo.getWithFallback(true);
269 if (info_fallback == null) {
270 errln("getWithFallback() returned null.");
274 CurrencyData.DefaultInfo info_nofallback = (CurrencyData.DefaultInfo)CurrencyData.DefaultInfo.getWithFallback(false);
275 if (info_nofallback == null) {
276 errln("getWithFallback() returned null.");
280 if (!info_fallback.getName("isoCode").equals("isoCode") || info_nofallback.getName("isoCode") != null) {
281 errln("Error calling getName().");
285 if (!info_fallback.getPluralName("isoCode", "type").equals("isoCode") || info_nofallback.getPluralName("isoCode", "type") != null) {
286 errln("Error calling getPluralName().");
290 if (!info_fallback.getSymbol("isoCode").equals("isoCode") || info_nofallback.getSymbol("isoCode") != null) {
291 errln("Error calling getSymbol().");
295 if (!info_fallback.symbolMap().isEmpty()) {
296 errln("symbolMap() should return empty map.");
300 if (!info_fallback.nameMap().isEmpty()) {
301 errln("nameMap() should return empty map.");
305 if (!info_fallback.getUnitPatterns().isEmpty() || info_nofallback.getUnitPatterns() != null) {
306 errln("Error calling getUnitPatterns().");
310 if (!info_fallback.getSpacingInfo().equals((CurrencyData.CurrencySpacingInfo.DEFAULT)) ||
311 info_nofallback.getSpacingInfo() != null) {
312 errln("Error calling getSpacingInfo().");
316 if (info_fallback.getULocale() != ULocale.ROOT) {
317 errln("Error calling getLocale().");
321 if (info_fallback.getFormatInfo("isoCode") != null) {
322 errln("Error calling getFormatInfo().");
327 // A real test of CurrencyMetaInfo.
328 public void testCurrencyMetaInfoRanges() {
329 CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance(true);
330 assertNotNull("have metainfo", metainfo);
332 CurrencyFilter filter = CurrencyFilter.onRegion("DE"); // must be capitalized
333 List<CurrencyInfo> currenciesInGermany = metainfo.currencyInfo(filter);
334 logln("currencies: " + currenciesInGermany.size());
335 DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
336 fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
337 Date demLastDate = new Date(Long.MAX_VALUE);
338 Date eurFirstDate = new Date(Long.MIN_VALUE);
339 for (CurrencyInfo info : currenciesInGermany) {
340 logln(info.toString());
341 logln("from: " + fmt.format(info.from)+ Long.toHexString(info.from));
342 logln(" to: " + fmt.format(info.to) + Long.toHexString(info.to));
343 if (info.code.equals("DEM")) {
344 demLastDate = new Date(info.to);
345 } else if (info.code.equals("EUR")) {
346 eurFirstDate = new Date(info.from);
350 // the Euro and Deutschmark overlapped for several years
351 assertEquals("DEM available at last date", 2, metainfo.currencyInfo(filter.withDate(demLastDate)).size());
353 // demLastDate + 1 millisecond is not the start of the last day, we consider it the next day, so...
354 Date demLastDatePlus1ms = new Date(demLastDate.getTime() + 1);
355 assertEquals("DEM not available after very start of last date", 1, metainfo.currencyInfo(filter.withDate(demLastDatePlus1ms)).size());
357 // both available for start of euro
358 assertEquals("EUR available on start of first date", 2, metainfo.currencyInfo(filter.withDate(eurFirstDate)).size());
360 // but not one millisecond before the start of the first day
361 Date eurFirstDateMinus1ms = new Date(eurFirstDate.getTime() - 1);
362 assertEquals("EUR not avilable before very start of first date", 1, metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
364 // end time is last millisecond of day
365 GregorianCalendar cal = new GregorianCalendar();
366 cal.setTimeZone(TimeZone.getTimeZone("GMT"));
367 cal.setTime(demLastDate);
368 assertEquals("hour is 23", 23, cal.get(GregorianCalendar.HOUR_OF_DAY));
369 assertEquals("minute is 59", 59, cal.get(GregorianCalendar.MINUTE));
370 assertEquals("second is 59", 59, cal.get(GregorianCalendar.SECOND));
371 assertEquals("millisecond is 999", 999, cal.get(GregorianCalendar.MILLISECOND));
373 // start time is first millisecond of day
374 cal.setTime(eurFirstDate);
375 assertEquals("hour is 0", 0, cal.get(GregorianCalendar.HOUR_OF_DAY));
376 assertEquals("minute is 0", 0, cal.get(GregorianCalendar.MINUTE));
377 assertEquals("second is 0", 0, cal.get(GregorianCalendar.SECOND));
378 assertEquals("millisecond is 0", 0, cal.get(GregorianCalendar.MILLISECOND));
381 public void testCurrencyMetaInfoRangesWithLongs() {
382 CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance(true);
383 assertNotNull("have metainfo", metainfo);
385 CurrencyFilter filter = CurrencyFilter.onRegion("DE"); // must be capitalized
386 List<CurrencyInfo> currenciesInGermany = metainfo.currencyInfo(filter);
387 logln("currencies: " + currenciesInGermany.size());
388 long demLastDate = Long.MAX_VALUE;
389 long eurFirstDate = Long.MIN_VALUE;
390 for (CurrencyInfo info : currenciesInGermany) {
391 logln(info.toString());
392 if (info.code.equals("DEM")) {
393 demLastDate = info.to;
394 } else if (info.code.equals("EUR")) {
395 eurFirstDate = info.from;
398 // the Euro and Deutschmark overlapped for several years
399 assertEquals("DEM available at last date", 2, metainfo.currencyInfo(filter.withDate(demLastDate)).size());
401 // demLastDate + 1 millisecond is not the start of the last day, we consider it the next day, so...
402 long demLastDatePlus1ms = demLastDate + 1;
403 assertEquals("DEM not available after very start of last date", 1, metainfo.currencyInfo(filter.withDate(demLastDatePlus1ms)).size());
405 // both available for start of euro
406 assertEquals("EUR available on start of first date", 2, metainfo.currencyInfo(filter.withDate(eurFirstDate)).size());
408 // but not one millisecond before the start of the first day
409 long eurFirstDateMinus1ms = eurFirstDate - 1;
410 assertEquals("EUR not avilable before very start of first date", 1, metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
413 public void TestWithTender() {
414 CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance();
415 if (metainfo == null) {
416 errln("Unable to get CurrencyMetaInfo instance.");
419 CurrencyMetaInfo.CurrencyFilter filter =
420 CurrencyMetaInfo.CurrencyFilter.onRegion("CH");
421 List<String> currencies = metainfo.currencies(filter);
422 assertTrue("More than one currency for switzerland", currencies.size() > 1);
425 Arrays.asList(new String[] {"CHF"}),
426 metainfo.currencies(filter.withTender()));
429 // Coverage-only test of the CurrencyMetaInfo class
430 public void TestCurrencyMetaInfo() {
431 CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance();
432 if (metainfo == null) {
433 errln("Unable to get CurrencyMetaInfo instance.");
437 if (!CurrencyMetaInfo.hasData()) {
438 errln("hasData() should note return false.");
442 CurrencyMetaInfo.CurrencyFilter filter;
443 CurrencyMetaInfo.CurrencyInfo info;
444 CurrencyMetaInfo.CurrencyDigits digits;
447 filter = CurrencyMetaInfo.CurrencyFilter.onCurrency("currency");
448 CurrencyMetaInfo.CurrencyFilter filter2 = CurrencyMetaInfo.CurrencyFilter.onCurrency("test");
449 if (filter == null) {
450 errln("Unable to create CurrencyFilter.");
454 if (filter.equals(new Object())) {
455 errln("filter should not equal to Object");
459 if (filter.equals(filter2)) {
460 errln("filter should not equal filter2");
464 if (filter.hashCode() == 0) {
465 errln("Error getting filter hashcode");
469 if (filter.toString() == null) {
470 errln("Error calling toString()");
476 info = new CurrencyMetaInfo.CurrencyInfo("region", "code", 0, 1, 1, false);
478 errln("Error creating CurrencyInfo.");
482 if (info.toString() == null) {
483 errln("Error calling toString()");
489 digits = metainfo.currencyDigits("isoCode");
490 if (digits == null) {
491 errln("Unable to get CurrencyDigits.");
495 if (digits.toString() == null) {
496 errln("Error calling toString()");
502 public void TestCurrencyKeyword() {
503 ULocale locale = new ULocale("th_TH@collation=traditional;currency=QQQ");
504 Currency currency = Currency.getInstance(locale);
505 String result = currency.getCurrencyCode();
506 if (!"QQQ".equals(result)) {
507 errln("got unexpected currency: " + result);
511 public void TestAvailableCurrencyCodes() {
513 { "eo_AM", "1950-01-05" },
514 { "eo_AM", "1969-12-31", "SUR" },
515 { "eo_AM", "1991-12-26", "RUR" },
516 { "eo_AM", "2000-12-23", "AMD" },
517 { "eo_AD", "2000-12-23", "EUR", "ESP", "FRF", "ADP" },
518 { "eo_AD", "1969-12-31", "ESP", "FRF", "ADP" },
519 { "eo_AD", "1950-01-05", "ESP", "ADP" },
520 { "eo_AD", "1900-01-17", "ESP" },
521 { "eo_UA", "1994-12-25" },
522 { "eo_QQ", "1969-12-31" },
523 { "eo_AO", "2000-12-23", "AOA" },
524 { "eo_AO", "1995-12-25", "AOR", "AON" },
525 { "eo_AO", "1990-12-26", "AON", "AOK" },
526 { "eo_AO", "1979-12-29", "AOK" },
527 { "eo_AO", "1969-12-31" },
528 { "eo_DE@currency=DEM", "2000-12-23", "EUR", "DEM" },
529 { "eo-DE-u-cu-dem", "2000-12-23", "EUR", "DEM" },
530 { "en_US", null, "USD" },
531 { "en_US_PREEURO", null, "USD" },
532 { "en_US_Q", null, "USD" },
535 DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
536 for (String[] test : tests) {
537 ULocale locale = new ULocale(test[0]);
538 String timeString = test[1];
540 if (timeString == null) {
542 timeString = "today";
545 date = fmt.parse(timeString);
546 } catch (Exception e) {
547 fail("could not parse date: " + timeString);
551 String[] expected = null;
552 if (test.length > 2) {
553 expected = new String[test.length - 2];
554 System.arraycopy(test, 2, expected, 0, expected.length);
556 String[] actual = Currency.getAvailableCurrencyCodes(locale, date);
558 // Order is not important as of 4.4. We never documented that it was.
559 Set<String> expectedSet = new HashSet<String>();
560 if (expected != null) {
561 expectedSet.addAll(Arrays.asList(expected));
563 Set<String> actualSet = new HashSet<String>();
564 if (actual != null) {
565 actualSet.addAll(Arrays.asList(actual));
567 assertEquals(locale + " on " + timeString, expectedSet, actualSet);
571 public void TestDeprecatedCurrencyFormat() {
573 Locale locale = new Locale("sr", "QQ");
574 DecimalFormatSymbols icuSymbols = new
575 com.ibm.icu.text.DecimalFormatSymbols(locale);
576 String symbol = icuSymbols.getCurrencySymbol();
577 Currency currency = icuSymbols.getCurrency();
578 String expectCur = null;
579 String expectSym = "\u00A4";
580 if(!symbol.toString().equals(expectSym) || currency != null) {
581 errln("for " + locale + " expected " + expectSym+"/"+expectCur + " but got " + symbol+"/"+currency);
583 logln("for " + locale + " expected " + expectSym+"/"+expectCur + " and got " + symbol+"/"+currency);
587 public void TestGetKeywordValues(){
589 final String[][] PREFERRED = {
600 {"ar_PS", "ILS", "JOD"},
601 {"en@currency=CAD", "USD"},
602 {"fr@currency=ZZZ", "EUR"},
603 {"de_DE@currency=DEM", "EUR"},
606 String[] ALL = Currency.getKeywordValuesForLocale("currency", ULocale.getDefault(), false);
607 HashSet ALLSET = new HashSet();
608 for (int i = 0; i < ALL.length; i++) {
612 for (int i = 0; i < PREFERRED.length; i++) {
613 ULocale loc = new ULocale(PREFERRED[i][0]);
614 String[] expected = new String[PREFERRED[i].length - 1];
615 System.arraycopy(PREFERRED[i], 1, expected, 0, expected.length);
616 String[] pref = Currency.getKeywordValuesForLocale("currency", loc, true);
617 assertEquals(loc.toString(), expected, pref);
619 String[] all = Currency.getKeywordValuesForLocale("currency", loc, false);
620 // The items in the two collections should match (ignore order,
621 // behavior change from 4.3.3)
622 Set<String> returnedSet = new HashSet<String>();
623 returnedSet.addAll(Arrays.asList(all));
624 assertEquals(loc.toString(), ALLSET, returnedSet);
628 public void TestIsAvailable() {
629 Date d1995 = new Date(788918400000L); // 1995-01-01 00:00 GMT
630 Date d2000 = new Date(946684800000L); // 2000-01-01 00:00 GMT
631 Date d2005 = new Date(1104537600000L); // 2005-01-01 00:00 GMT
633 assertTrue("USD all time", Currency.isAvailable("USD", null, null));
634 assertTrue("USD before 1995", Currency.isAvailable("USD", null, d1995));
635 assertTrue("USD 1995-2005", Currency.isAvailable("USD", d1995, d2005));
636 assertTrue("USD after 2005", Currency.isAvailable("USD", d2005, null));
637 assertTrue("USD on 2005-01-01", Currency.isAvailable("USD", d2005, d2005));
639 assertTrue("usd all time", Currency.isAvailable("usd", null, null));
641 assertTrue("DEM all time", Currency.isAvailable("DEM", null, null));
642 assertTrue("DEM before 1995", Currency.isAvailable("DEM", null, d1995));
643 assertTrue("DEM 1995-2000", Currency.isAvailable("DEM", d1995, d2000));
644 assertTrue("DEM 1995-2005", Currency.isAvailable("DEM", d1995, d2005));
645 assertFalse("DEM after 2005", Currency.isAvailable("DEM", d2005, null));
646 assertTrue("DEM on 2000-01-01", Currency.isAvailable("DEM", d2000, d2000));
647 assertFalse("DEM on 2005-01-01", Currency.isAvailable("DEM", d2005, d2005));
648 assertTrue("CHE all the time", Currency.isAvailable("CHE", null, null));
650 assertFalse("XXY unknown code", Currency.isAvailable("XXY", null, null));
652 assertFalse("USDOLLAR invalid code", Currency.isAvailable("USDOLLAR", null, null));
654 // illegal argument combination
656 Currency.isAvailable("USD", d2005, d1995);
657 errln("Expected IllegalArgumentException, because lower range is after upper range");
658 } catch (IllegalArgumentException e) {
659 logln("IllegalArgumentException, because lower range is after upper range");
664 * Test case for getAvailableCurrencies()
666 public void TestGetAvailableCurrencies() {
667 Set<Currency> avail1 = Currency.getAvailableCurrencies();
669 // returned set must be modifiable - add one more currency
670 avail1.add(Currency.getInstance("ZZZ")); // ZZZ is not defined by ISO 4217
672 Set<Currency> avail2 = Currency.getAvailableCurrencies();
673 assertTrue("avail1 does not contain all currencies in avail2", avail1.containsAll(avail2));
674 assertTrue("avail1 must have one more currency", (avail1.size() - avail2.size() == 1));
678 * Test case for getNumericCode()
680 public void TestGetNumericCode() {
681 final Object[][] NUMCODE_TESTDATA = {
683 {"Usd", 840}, /* mixed casing */
686 {"XFU", 0}, /* XFU: no numeric code */
687 {"ZZZ", 0}, /* ZZZ: undefined ISO currency code */
690 for (Object[] data : NUMCODE_TESTDATA) {
691 Currency cur = Currency.getInstance((String)data[0]);
692 int numCode = cur.getNumericCode();
693 int expected = ((Integer)data[1]).intValue();
694 if (numCode != expected) {
695 errln("FAIL: getNumericCode returned " + numCode + " for "
696 + cur.getCurrencyCode() + " - expected: " + expected);
702 * Test case for getDisplayName()
704 public void TestGetDisplayName() {
705 final String[][] DISPNAME_TESTDATA = {
706 {"USD", "US Dollar"},
708 {"JPY", "Japanese Yen"},
711 Locale defLocale = Locale.getDefault();
712 Locale jaJP = new Locale("ja", "JP");
713 Locale root = new Locale("");
715 for (String[] data : DISPNAME_TESTDATA) {
716 Currency cur = Currency.getInstance(data[0]);
717 assertEquals("getDisplayName() for " + data[0], data[1], cur.getDisplayName());
718 assertEquals("getDisplayName() for " + data[0] + " in locale " + defLocale, data[1], cur.getDisplayName(defLocale));
720 // ICU has localized display name for ja
721 assertNotEquals("getDisplayName() for " + data[0] + " in locale " + jaJP, data[1], cur.getDisplayName(jaJP));
723 // root locale does not have any localized display names,
724 // so the currency code itself should be returned
725 assertEquals("getDisplayName() for " + data[0] + " in locale " + root, data[0], cur.getDisplayName(root));
729 public void TestCurrencyInfoCtor() {
730 new CurrencyMetaInfo.CurrencyInfo("region", "code", 0, 0, 1);