1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
26
26
* @bug 4406815 8222969 8266784
27
27
* @summary RuleBasedCollatorTest uses very limited but selected test data
28
28
* to test basic functionalities provided by RuleBasedCollator.
29
- * @run testng /othervm RuleBasedCollatorTest
29
+ * @run junit /othervm RuleBasedCollatorTest
30
30
*/
31
31
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
+
32
38
import java .text .CollationElementIterator ;
33
39
import java .text .CollationKey ;
34
- import java .text .RuleBasedCollator ;
35
40
import java .text .Collator ;
36
41
import java .text .ParseException ;
42
+ import java .text .RuleBasedCollator ;
37
43
import java .util .Arrays ;
38
44
import java .util .Locale ;
39
45
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 ;
45
52
53
+ @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
46
54
public class RuleBasedCollatorTest {
47
55
48
- static RuleBasedCollator USC ;
49
- static String US_RULES ;
56
+ private static RuleBasedCollator USC ;
57
+ private static String US_RULES ;
50
58
51
- @ BeforeClass
52
- public void setup () {
59
+ @ BeforeAll
60
+ void setup () {
53
61
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." );
57
63
USC = (RuleBasedCollator ) c ;
58
64
US_RULES = USC .getRules ();
59
65
}
60
66
61
67
62
- @ DataProvider (name = "rulesData" )
63
68
Object [][] rulesData () {
64
69
//Basic Tailor
65
70
String BASIC_TAILOR_RULES = "< b=c<\u00e6 ;A,a" ;
@@ -91,15 +96,15 @@ Object[][] rulesData() {
91
96
};
92
97
}
93
98
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 )
96
102
throws ParseException {
97
103
Arrays .sort (testData , new RuleBasedCollator (rules ));
98
- assertEquals ( testData , expected );
104
+ assertArrayEquals ( expected , testData );
99
105
100
106
}
101
107
102
- @ DataProvider (name = "FrenchSecondarySort" )
103
108
Object [][] FrenchSecondarySort () {
104
109
return new Object [][] {
105
110
{ "\u0061 \u00e1 \u0061 " , "\u00e1 \u0061 \u0061 " , 1 },
@@ -111,8 +116,9 @@ Object[][] FrenchSecondarySort() {
111
116
{ "a" , "\u1ea1 " , -1 } };
112
117
}
113
118
114
- @ Test (dataProvider = "FrenchSecondarySort" )
115
- public void testFrenchSecondarySort (String sData , String tData ,
119
+ @ ParameterizedTest
120
+ @ MethodSource ("FrenchSecondarySort" )
121
+ void testFrenchSecondarySort (String sData , String tData ,
116
122
int expected ) throws ParseException {
117
123
String french_rule = "@" ;
118
124
String rules = US_RULES + french_rule ;
@@ -121,16 +127,16 @@ public void testFrenchSecondarySort(String sData, String tData,
121
127
assertEquals (expected , result );
122
128
}
123
129
124
- @ DataProvider (name = "ThaiLaoVowelConsonantSwapping" )
125
130
Object [][] ThaiLaoVowelConsonantSwapping () {
126
131
return new Object [][] {{"\u0e44 \u0e01 " , "\u0e40 \u0e2e " , -1 },//swap
127
132
{"\u0e2e \u0e40 " , "\u0e01 \u0e44 " , 1 },//no swap
128
133
{"\u0e44 \u0061 " , "\u0e40 \u0081 " , 1 }//no swap
129
134
};
130
135
}
131
136
132
- @ Test (dataProvider = "ThaiLaoVowelConsonantSwapping" )
133
- public void testThaiLaoVowelConsonantSwapping (String sData , String tData ,
137
+ @ ParameterizedTest
138
+ @ MethodSource ("ThaiLaoVowelConsonantSwapping" )
139
+ void testThaiLaoVowelConsonantSwapping (String sData , String tData ,
134
140
int expected ) throws ParseException {
135
141
String thai_rule = "& Z < \u0e01 < \u0e2e <\u0e40 < \u0e44 !" ;
136
142
String rules = US_RULES + thai_rule ;
@@ -140,16 +146,15 @@ public void testThaiLaoVowelConsonantSwapping(String sData, String tData,
140
146
}
141
147
142
148
@ Test
143
- public void testIgnorableCharacter () throws ParseException {
149
+ void testIgnorableCharacter () throws ParseException {
144
150
String rule = "=f<a<c" ;
145
151
RuleBasedCollator rc = new RuleBasedCollator (rule );
146
152
CollationElementIterator iter = rc .getCollationElementIterator ("f" );
147
153
int element = iter .next ();
148
154
int primary = iter .primaryOrder (element );
149
- assertEquals (primary , 0 );
155
+ assertEquals (0 , primary );
150
156
}
151
157
152
- @ DataProvider (name = "Normalization" )
153
158
Object [][] Normalization () {
154
159
return new Object [][] {
155
160
//micro sign has no canonical decomp mapping
@@ -162,16 +167,17 @@ Object[][] Normalization() {
162
167
};
163
168
}
164
169
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 ,
167
173
int result ) {
168
174
RuleBasedCollator rc = (RuleBasedCollator )USC .clone ();
169
175
rc .setDecomposition (decomp );
170
- assertEquals (rc .compare (sData , tData ), result );
176
+ assertEquals (result , rc .compare (sData , tData ));
171
177
}
172
178
173
179
@ Test
174
- public void testEquality () throws ParseException {
180
+ void testEquality () throws ParseException {
175
181
String rule1 = "<a=b" ;
176
182
RuleBasedCollator rc1 = new RuleBasedCollator (rule1 );
177
183
//test equals()
@@ -186,12 +192,12 @@ public void testEquality() throws ParseException {
186
192
187
193
Arrays .sort (array1 , rc1 );
188
194
Arrays .sort (array2 , rc2 );
189
- assertEquals ( array1 , array2 );
190
- assertEquals ( array1 , expected );
195
+ assertArrayEquals ( array2 , array1 );
196
+ assertArrayEquals ( expected , array1 );
191
197
}
192
198
193
199
@ Test
194
- public void testBasicParsingOrder () throws ParseException {
200
+ void testBasicParsingOrder () throws ParseException {
195
201
String rule1 = "< a < b & a < c" ;
196
202
String rule2 = "< a < c & a < b" ;
197
203
String rule3 = "< a < b < c" ;
@@ -203,13 +209,12 @@ public void testBasicParsingOrder() throws ParseException {
203
209
CollationKey k2 = c2 .getCollationKey (s );
204
210
CollationKey k3 = c3 .getCollationKey (s );
205
211
//rule1 should not equals to rule2
206
- assertEquals ( k1 .compareTo (k2 ) == 0 , false );
212
+ assertNotEquals ( 0 , k1 .compareTo (k2 ));
207
213
208
214
//rule2 should equals to rule3
209
- assertEquals (k2 .compareTo (k3 ) == 0 , true );
215
+ assertEquals (0 , k2 .compareTo (k3 ));
210
216
}
211
217
212
- @ DataProvider (name = "ParseData" )
213
218
Object [][] ParseData () {
214
219
return new Object [][] {
215
220
{"" },
@@ -220,14 +225,14 @@ Object[][] ParseData() {
220
225
};
221
226
}
222
227
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 ) );
227
232
}
228
233
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 ) );
232
237
}
233
238
}
0 commit comments