Skip to content

Commit 12c0f29

Browse files
author
Justin Lu
committed
8368498: Use JUnit instead of TestNG for jdk_text tests
Reviewed-by: naoto
1 parent c6cecc5 commit 12c0f29

21 files changed

+488
-375
lines changed

test/jdk/java/text/Collator/RuleBasedCollatorTest.java

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -26,40 +26,45 @@
2626
* @bug 4406815 8222969 8266784
2727
* @summary RuleBasedCollatorTest uses very limited but selected test data
2828
* to test basic functionalities provided by RuleBasedCollator.
29-
* @run testng/othervm RuleBasedCollatorTest
29+
* @run junit/othervm RuleBasedCollatorTest
3030
*/
3131

32+
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.TestInstance;
35+
import org.junit.jupiter.params.ParameterizedTest;
36+
import org.junit.jupiter.params.provider.MethodSource;
37+
3238
import java.text.CollationElementIterator;
3339
import java.text.CollationKey;
34-
import java.text.RuleBasedCollator;
3540
import java.text.Collator;
3641
import java.text.ParseException;
42+
import java.text.RuleBasedCollator;
3743
import java.util.Arrays;
3844
import java.util.Locale;
3945

40-
import org.testng.annotations.BeforeClass;
41-
import org.testng.annotations.DataProvider;
42-
import org.testng.annotations.Test;
43-
import org.testng.SkipException;
44-
import static org.testng.Assert.*;
46+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
47+
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
49+
import static org.junit.jupiter.api.Assertions.assertThrows;
50+
import static org.junit.jupiter.api.Assertions.assertTrue;
51+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
4552

53+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4654
public class RuleBasedCollatorTest {
4755

48-
static RuleBasedCollator USC;
49-
static String US_RULES;
56+
private static RuleBasedCollator USC;
57+
private static String US_RULES;
5058

51-
@BeforeClass
52-
public void setup() {
59+
@BeforeAll
60+
void setup() {
5361
Collator c = Collator.getInstance(Locale.US);
54-
if (!(c instanceof RuleBasedCollator)) {
55-
throw new SkipException("skip tests.");
56-
}
62+
assumeFalse(!(c instanceof RuleBasedCollator), "skip tests.");
5763
USC = (RuleBasedCollator) c;
5864
US_RULES = USC.getRules();
5965
}
6066

6167

62-
@DataProvider(name = "rulesData")
6368
Object[][] rulesData() {
6469
//Basic Tailor
6570
String BASIC_TAILOR_RULES = "< b=c<\u00e6;A,a";
@@ -91,15 +96,15 @@ Object[][] rulesData() {
9196
};
9297
}
9398

94-
@Test(dataProvider = "rulesData")
95-
public void testRules(String rules, String[] testData, String[] expected)
99+
@ParameterizedTest
100+
@MethodSource("rulesData")
101+
void testRules(String rules, String[] testData, String[] expected)
96102
throws ParseException {
97103
Arrays.sort(testData, new RuleBasedCollator(rules));
98-
assertEquals(testData, expected);
104+
assertArrayEquals(expected, testData);
99105

100106
}
101107

102-
@DataProvider(name = "FrenchSecondarySort")
103108
Object[][] FrenchSecondarySort() {
104109
return new Object[][] {
105110
{ "\u0061\u00e1\u0061", "\u00e1\u0061\u0061", 1 },
@@ -111,8 +116,9 @@ Object[][] FrenchSecondarySort() {
111116
{ "a", "\u1ea1", -1 } };
112117
}
113118

114-
@Test(dataProvider = "FrenchSecondarySort")
115-
public void testFrenchSecondarySort(String sData, String tData,
119+
@ParameterizedTest
120+
@MethodSource("FrenchSecondarySort")
121+
void testFrenchSecondarySort(String sData, String tData,
116122
int expected) throws ParseException {
117123
String french_rule = "@";
118124
String rules = US_RULES + french_rule;
@@ -121,16 +127,16 @@ public void testFrenchSecondarySort(String sData, String tData,
121127
assertEquals(expected, result);
122128
}
123129

124-
@DataProvider(name = "ThaiLaoVowelConsonantSwapping")
125130
Object[][] ThaiLaoVowelConsonantSwapping() {
126131
return new Object[][] {{"\u0e44\u0e01", "\u0e40\u0e2e", -1},//swap
127132
{"\u0e2e\u0e40", "\u0e01\u0e44", 1},//no swap
128133
{"\u0e44\u0061", "\u0e40\u0081", 1}//no swap
129134
};
130135
}
131136

132-
@Test(dataProvider = "ThaiLaoVowelConsonantSwapping")
133-
public void testThaiLaoVowelConsonantSwapping(String sData, String tData,
137+
@ParameterizedTest
138+
@MethodSource("ThaiLaoVowelConsonantSwapping")
139+
void testThaiLaoVowelConsonantSwapping(String sData, String tData,
134140
int expected) throws ParseException {
135141
String thai_rule = "& Z < \u0e01 < \u0e2e <\u0e40 < \u0e44!";
136142
String rules = US_RULES + thai_rule;
@@ -140,16 +146,15 @@ public void testThaiLaoVowelConsonantSwapping(String sData, String tData,
140146
}
141147

142148
@Test
143-
public void testIgnorableCharacter() throws ParseException {
149+
void testIgnorableCharacter() throws ParseException {
144150
String rule = "=f<a<c";
145151
RuleBasedCollator rc = new RuleBasedCollator(rule);
146152
CollationElementIterator iter = rc.getCollationElementIterator("f");
147153
int element = iter.next();
148154
int primary = iter.primaryOrder(element);
149-
assertEquals(primary, 0);
155+
assertEquals(0, primary);
150156
}
151157

152-
@DataProvider(name = "Normalization")
153158
Object[][] Normalization() {
154159
return new Object[][] {
155160
//micro sign has no canonical decomp mapping
@@ -162,16 +167,17 @@ Object[][] Normalization() {
162167
};
163168
}
164169

165-
@Test(dataProvider = "Normalization")
166-
public void testNormalization(String sData, String tData, int decomp,
170+
@ParameterizedTest
171+
@MethodSource("Normalization")
172+
void testNormalization(String sData, String tData, int decomp,
167173
int result) {
168174
RuleBasedCollator rc = (RuleBasedCollator)USC.clone();
169175
rc.setDecomposition(decomp);
170-
assertEquals(rc.compare(sData, tData), result);
176+
assertEquals(result, rc.compare(sData, tData));
171177
}
172178

173179
@Test
174-
public void testEquality() throws ParseException {
180+
void testEquality() throws ParseException {
175181
String rule1 = "<a=b";
176182
RuleBasedCollator rc1= new RuleBasedCollator(rule1);
177183
//test equals()
@@ -186,12 +192,12 @@ public void testEquality() throws ParseException {
186192

187193
Arrays.sort(array1, rc1);
188194
Arrays.sort(array2, rc2);
189-
assertEquals(array1, array2);
190-
assertEquals(array1, expected);
195+
assertArrayEquals(array2, array1);
196+
assertArrayEquals(expected, array1);
191197
}
192198

193199
@Test
194-
public void testBasicParsingOrder() throws ParseException {
200+
void testBasicParsingOrder() throws ParseException {
195201
String rule1 = "< a < b & a < c";
196202
String rule2 = "< a < c & a < b";
197203
String rule3 = "< a < b < c";
@@ -203,13 +209,12 @@ public void testBasicParsingOrder() throws ParseException {
203209
CollationKey k2 = c2.getCollationKey(s);
204210
CollationKey k3 = c3.getCollationKey(s);
205211
//rule1 should not equals to rule2
206-
assertEquals(k1.compareTo(k2) == 0, false);
212+
assertNotEquals(0, k1.compareTo(k2));
207213

208214
//rule2 should equals to rule3
209-
assertEquals(k2.compareTo(k3) == 0, true);
215+
assertEquals(0, k2.compareTo(k3));
210216
}
211217

212-
@DataProvider(name = "ParseData")
213218
Object[][] ParseData() {
214219
return new Object[][] {
215220
{""},
@@ -220,14 +225,14 @@ Object[][] ParseData() {
220225
};
221226
}
222227

223-
@Test(dataProvider = "ParseData",
224-
expectedExceptions = ParseException.class)
225-
public void testParseException(String rule) throws ParseException{
226-
new RuleBasedCollator(rule);
228+
@ParameterizedTest
229+
@MethodSource("ParseData")
230+
void testParseException(String rule) {
231+
assertThrows(ParseException.class, () -> new RuleBasedCollator(rule));
227232
}
228233

229-
@Test(expectedExceptions = NullPointerException.class)
230-
public void testNullParseException() throws ParseException{
231-
new RuleBasedCollator(null);
234+
@Test
235+
void testNullParseException() {
236+
assertThrows(NullPointerException.class, () -> new RuleBasedCollator(null));
232237
}
233238
}

test/jdk/java/text/Format/CompactNumberFormat/CompactFormatAndParseHelper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, 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
@@ -24,14 +24,15 @@
2424
import java.text.NumberFormat;
2525
import java.text.ParseException;
2626
import java.text.ParsePosition;
27-
import static org.testng.Assert.assertEquals;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2829

2930
class CompactFormatAndParseHelper {
3031

3132
static void testFormat(NumberFormat cnf, Object number,
3233
String expected) {
3334
String result = cnf.format(number);
34-
assertEquals(result, expected, "Incorrect formatting of the number '"
35+
assertEquals(expected, result, "Incorrect formatting of the number '"
3536
+ number + "'");
3637
}
3738

@@ -46,11 +47,11 @@ static void testParse(NumberFormat cnf, String parseString,
4647
}
4748

4849
if (returnType != null) {
49-
assertEquals(number.getClass(), returnType,
50+
assertEquals(returnType, number.getClass(),
5051
"Incorrect return type for string '" + parseString + "'");
5152
}
5253

53-
assertEquals(number, expected, "Incorrect parsing of the string '"
54+
assertEquals(expected, number, "Incorrect parsing of the string '"
5455
+ parseString + "'");
5556
}
5657
}

test/jdk/java/text/Format/CompactNumberFormat/TestCNFRounding.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, 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,21 +20,28 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
2324
/*
2425
* @test
2526
* @bug 8177552
2627
* @summary Checks the rounding of formatted number in compact number formatting
27-
* @run testng/othervm TestCNFRounding
28+
* @run junit/othervm TestCNFRounding
2829
*/
2930

31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.TestInstance;
33+
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.MethodSource;
35+
3036
import java.math.RoundingMode;
3137
import java.text.NumberFormat;
3238
import java.util.List;
3339
import java.util.Locale;
34-
import static org.testng.Assert.*;
35-
import org.testng.annotations.DataProvider;
36-
import org.testng.annotations.Test;
3740

41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertThrows;
43+
44+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3845
public class TestCNFRounding {
3946

4047
private static final List<RoundingMode> MODES = List.of(
@@ -46,7 +53,6 @@ public class TestCNFRounding {
4653
RoundingMode.CEILING,
4754
RoundingMode.FLOOR);
4855

49-
@DataProvider(name = "roundingData")
5056
Object[][] roundingData() {
5157
return new Object[][]{
5258
// Number, half_even, half_up, half_down, up, down, ceiling, floor
@@ -70,7 +76,6 @@ Object[][] roundingData() {
7076
{-4500, new String[]{"-4K", "-5K", "-4K", "-5K", "-4K", "-4K", "-5K"}},};
7177
}
7278

73-
@DataProvider(name = "roundingFract")
7479
Object[][] roundingFract() {
7580
return new Object[][]{
7681
// Number, half_even, half_up, half_down, up, down, ceiling, floor
@@ -94,7 +99,6 @@ Object[][] roundingFract() {
9499
{-4500, new String[]{"-4.5K", "-4.5K", "-4.5K", "-4.5K", "-4.5K", "-4.5K", "-4.5K"}},};
95100
}
96101

97-
@DataProvider(name = "rounding2Fract")
98102
Object[][] rounding2Fract() {
99103
return new Object[][]{
100104
// Number, half_even, half_up, half_down
@@ -118,37 +122,42 @@ Object[][] rounding2Fract() {
118122
{4686, new String[]{"4.69K", "4.69K", "4.69K"}},};
119123
}
120124

121-
@Test(expectedExceptions = NullPointerException.class)
122-
public void testNullMode() {
123-
NumberFormat fmt = NumberFormat
124-
.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
125-
fmt.setRoundingMode(null);
125+
@Test
126+
void testNullMode() {
127+
assertThrows(NullPointerException.class, () -> {
128+
NumberFormat fmt = NumberFormat
129+
.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
130+
fmt.setRoundingMode(null);
131+
});
126132
}
127133

128134
@Test
129-
public void testDefaultRoundingMode() {
135+
void testDefaultRoundingMode() {
130136
NumberFormat fmt = NumberFormat
131137
.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
132-
assertEquals(fmt.getRoundingMode(), RoundingMode.HALF_EVEN,
138+
assertEquals(RoundingMode.HALF_EVEN, fmt.getRoundingMode(),
133139
"Default RoundingMode should be " + RoundingMode.HALF_EVEN);
134140
}
135141

136-
@Test(dataProvider = "roundingData")
137-
public void testRounding(Object number, String[] expected) {
142+
@ParameterizedTest
143+
@MethodSource("roundingData")
144+
void testRounding(Object number, String[] expected) {
138145
for (int index = 0; index < MODES.size(); index++) {
139146
testRoundingMode(number, expected[index], 0, MODES.get(index));
140147
}
141148
}
142149

143-
@Test(dataProvider = "roundingFract")
144-
public void testRoundingFract(Object number, String[] expected) {
150+
@ParameterizedTest
151+
@MethodSource("roundingFract")
152+
void testRoundingFract(Object number, String[] expected) {
145153
for (int index = 0; index < MODES.size(); index++) {
146154
testRoundingMode(number, expected[index], 1, MODES.get(index));
147155
}
148156
}
149157

150-
@Test(dataProvider = "rounding2Fract")
151-
public void testRounding2Fract(Object number, String[] expected) {
158+
@ParameterizedTest
159+
@MethodSource("rounding2Fract")
160+
void testRounding2Fract(Object number, String[] expected) {
152161
List<RoundingMode> rModes = List.of(RoundingMode.HALF_EVEN,
153162
RoundingMode.HALF_UP, RoundingMode.HALF_DOWN);
154163
for (int index = 0; index < rModes.size(); index++) {
@@ -161,12 +170,12 @@ private void testRoundingMode(Object number, String expected,
161170
NumberFormat fmt = NumberFormat
162171
.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
163172
fmt.setRoundingMode(rounding);
164-
assertEquals(fmt.getRoundingMode(), rounding,
173+
assertEquals(rounding, fmt.getRoundingMode(),
165174
"RoundingMode set is not returned by getRoundingMode");
166175

167176
fmt.setMinimumFractionDigits(fraction);
168177
String result = fmt.format(number);
169-
assertEquals(result, expected, "Incorrect formatting of number "
178+
assertEquals(expected, result, "Incorrect formatting of number "
170179
+ number + " using rounding mode: " + rounding);
171180
}
172181

0 commit comments

Comments
 (0)