Skip to content

Commit ba59249

Browse files
committed
8310923: Refactor Currency tests to use JUnit
Backport-of: e848d9471f5de86e5ac157b710cd7371f12f0024
1 parent a51c74d commit ba59249

File tree

9 files changed

+717
-653
lines changed

9 files changed

+717
-653
lines changed

test/jdk/java/util/Currency/Bug4512215.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/jdk/java/util/Currency/Bug6807534.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

test/jdk/java/util/Currency/Bug8154295.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 6807534
27+
* @summary check whether the default implementation of
28+
* CurrencyNameProvider.getDisplayName(String, Locale) throws appropriate
29+
* exceptions when necessary.
30+
* @run junit CNPGetDisplayName
31+
*/
32+
33+
import java.util.Locale;
34+
import java.util.spi.CurrencyNameProvider;
35+
import java.util.stream.Stream;
36+
37+
import org.junit.jupiter.params.ParameterizedTest;
38+
import org.junit.jupiter.params.provider.Arguments;
39+
import org.junit.jupiter.params.provider.MethodSource;
40+
41+
import static org.junit.jupiter.api.Assertions.assertThrows;
42+
43+
public class CNPGetDisplayName {
44+
45+
static final CurrencyNameProvider cnp = new CurrencyNameProviderImpl();
46+
47+
/**
48+
* Tests that the currency name provider throws a NullPointerException
49+
* under the expected circumstances.
50+
*/
51+
@ParameterizedTest
52+
@MethodSource("nullArgProvider")
53+
public void NPETest(String currencyCode, Locale locale, String err) {
54+
assertThrows(NullPointerException.class,
55+
() -> cnp.getDisplayName(currencyCode, locale), err);
56+
}
57+
58+
/**
59+
* Tests that the currency name provider throws a IllegalArgumentException
60+
* under the expected circumstances.
61+
*/
62+
@ParameterizedTest
63+
@MethodSource("illegalArgProvider")
64+
public void IAETest(String currencyCode, Locale locale, String err) {
65+
assertThrows(IllegalArgumentException.class,
66+
() -> cnp.getDisplayName(currencyCode, locale), err);
67+
}
68+
69+
private static Stream<Arguments> nullArgProvider() {
70+
return Stream.of(
71+
Arguments.of(null, Locale.US,
72+
"NPE was not thrown with null currencyCode"),
73+
Arguments.of("USD", null,
74+
"NPE was not thrown with null locale")
75+
);
76+
}
77+
78+
private static Stream<Arguments> illegalArgProvider() {
79+
return Stream.of(
80+
Arguments.of("INVALID", Locale.US,
81+
"IAE was not thrown with invalid currency code"),
82+
Arguments.of("inv", Locale.US,
83+
"IAE was not thrown with invalid currency code"),
84+
Arguments.of("USD", Locale.JAPAN,
85+
"IllegalArgumentException was not thrown with non-supported locale")
86+
);
87+
}
88+
89+
static class CurrencyNameProviderImpl extends CurrencyNameProvider {
90+
// dummy implementation
91+
public String getSymbol(String currencyCode, Locale locale) {
92+
return "";
93+
}
94+
95+
public Locale[] getAvailableLocales() {
96+
Locale[] avail = new Locale[1];
97+
avail[0] = Locale.US;
98+
return avail;
99+
}
100+
}
101+
}

test/jdk/java/util/Currency/CheckDataVersion.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -20,15 +20,21 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
/**
24-
*
25-
*
26-
* Check the consistency between the regression tests and the currency data in the JRE
23+
24+
25+
/*
26+
Check the consistency between the regression tests and the currency
27+
data in the JRE. This class is used by other test classes.
2728
*/
2829

29-
import java.io.*;
30-
import java.lang.reflect.*;
31-
import java.security.*;
30+
import java.io.BufferedReader;
31+
import java.io.DataInputStream;
32+
import java.io.File;
33+
import java.io.FileReader;
34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.security.AccessController;
37+
import java.security.PrivilegedAction;
3238
import java.util.Currency;
3339

3440
class CheckDataVersion {

0 commit comments

Comments
 (0)