author | mfang |
Wed, 17 Aug 2011 14:18:26 -0700 | |
changeset 10294 | 8fcdae2a7ec7 |
parent 7255 | 88d0a8413bb8 |
permissions | -rw-r--r-- |
7255
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
1 |
/* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
4 |
* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
8 |
* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
13 |
* accompanied this code). |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
14 |
* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
18 |
* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
21 |
* questions. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
22 |
*/ |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
23 |
/* |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
24 |
* @test |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
25 |
* @bug 6807534 |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
26 |
* @summary check whether the default implementation of |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
27 |
* CurrencNameProvider.getDisplayName(String, Locale) throws appropriate |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
28 |
* exceptions when necessary. |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
29 |
*/ |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
30 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
31 |
import java.util.Locale; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
32 |
import java.util.spi.CurrencyNameProvider; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
33 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
34 |
public class Bug6807534 { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
35 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
36 |
static final CurrencyNameProvider cnp = new CurrencyNameProviderImpl(); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
37 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
39 |
// test for NullPointerException (currencyCode) |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
40 |
try { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
41 |
cnp.getDisplayName(null, Locale.US); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
42 |
throwException("NPE was not thrown with null currencyCode"); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
43 |
} catch (NullPointerException npe) {} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
44 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
45 |
// test for NullPointerException (locale) |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
46 |
try { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
47 |
cnp.getDisplayName("USD", null); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
48 |
throwException("NPE was not thrown with null locale"); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
49 |
} catch (NullPointerException npe) {} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
50 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
51 |
// test for IllegalArgumentException (illegal currencyCode) |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
52 |
try { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
53 |
cnp.getDisplayName("INVALID", Locale.US); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
54 |
throwException("IllegalArgumentException was not thrown with invalid currency code"); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
55 |
} catch (IllegalArgumentException iae) {} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
56 |
try { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
57 |
cnp.getDisplayName("inv", Locale.US); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
58 |
throwException("IllegalArgumentException was not thrown with invalid currency code"); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
59 |
} catch (IllegalArgumentException iae) {} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
60 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
61 |
// test for IllegalArgumentException (non-supported locale) |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
62 |
try { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
63 |
cnp.getDisplayName("USD", Locale.JAPAN); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
64 |
throwException("IllegalArgumentException was not thrown with non-supported locale"); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
65 |
} catch (IllegalArgumentException iae) {} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
66 |
} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
67 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
68 |
static void throwException(String msg) { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
69 |
throw new RuntimeException("test failed. "+msg); |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
70 |
} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
71 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
72 |
static class CurrencyNameProviderImpl extends CurrencyNameProvider { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
73 |
// dummy implementation |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
74 |
public String getSymbol(String currencyCode, Locale locale) { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
75 |
return ""; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
76 |
} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
77 |
|
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
78 |
public Locale[] getAvailableLocales() { |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
79 |
Locale[] avail = new Locale[1]; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
80 |
avail[0] = Locale.US; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
81 |
return avail; |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
82 |
} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
83 |
} |
88d0a8413bb8
6807534: CurrencyNameProvider.getDisplayName(String, Locale) doesn't throw IllegalArgumentException
naoto
parents:
diff
changeset
|
84 |
} |