1
1
/*
2
- * Copyright (c) 2020, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2020, 2023 , 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
23
23
24
24
package jdk .test .lib .format ;
25
25
26
- import org .testng . annotations .Test ;
26
+ import org .junit . jupiter . api .Test ;
27
27
28
- import static org .testng .Assert .assertTrue ;
29
- import static org .testng .Assert .assertFalse ;
30
- import static org .testng .Assert .assertEquals ;
28
+ import static org .junit .jupiter .api .Assertions .*;
31
29
32
30
/*
33
31
* @test
34
32
* @summary Check ArrayDiff formatting
35
33
* @library /test/lib
36
- * @run testng jdk.test.lib.format.ArrayDiffTest
34
+ * @run junit jdk.test.lib.format.ArrayDiffTest
37
35
*/
38
- public class ArrayDiffTest {
36
+ class ArrayDiffTest {
39
37
40
38
@ Test
41
- public void testEqualArrays () {
39
+ void testEqualArrays () {
42
40
char [] first = new char [] {'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' };
43
41
char [] second = new char [] {'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' };
44
42
45
43
assertTrue (ArrayDiff .of (first , second ).areEqual ());
46
44
}
47
45
48
46
@ Test
49
- public void testOutputFitsWidth () {
47
+ void testOutputFitsWidth () {
50
48
new AssertBuilder ()
51
49
.withDefaultParams ()
52
50
.withArrays (
@@ -62,7 +60,7 @@ public void testOutputFitsWidth() {
62
60
}
63
61
64
62
@ Test
65
- public void testIntegers () {
63
+ void testIntegers () {
66
64
new AssertBuilder ()
67
65
.withDefaultParams ()
68
66
.withArrays (
@@ -78,7 +76,7 @@ public void testIntegers() {
78
76
}
79
77
80
78
@ Test
81
- public void testLongs () {
79
+ void testLongs () {
82
80
new AssertBuilder ()
83
81
.withDefaultParams ()
84
82
.withArrays (
@@ -94,7 +92,7 @@ public void testLongs() {
94
92
}
95
93
96
94
@ Test
97
- public void testFirstElementIsWrong () {
95
+ void testFirstElementIsWrong () {
98
96
new AssertBuilder ()
99
97
.withDefaultParams ()
100
98
.withArrays (
@@ -110,7 +108,7 @@ public void testFirstElementIsWrong() {
110
108
}
111
109
112
110
@ Test
113
- public void testOneElementIsEmpty () {
111
+ void testOneElementIsEmpty () {
114
112
new AssertBuilder ()
115
113
.withDefaultParams ()
116
114
.withArrays (
@@ -126,7 +124,7 @@ public void testOneElementIsEmpty() {
126
124
}
127
125
128
126
@ Test
129
- public void testOutputDoesntFitWidth () {
127
+ void testOutputDoesntFitWidth () {
130
128
new AssertBuilder ()
131
129
.withParams (20 , Integer .MAX_VALUE )
132
130
.withArrays (
@@ -142,7 +140,7 @@ public void testOutputDoesntFitWidth() {
142
140
}
143
141
144
142
@ Test
145
- public void testVariableElementWidthOutputDoesntFitWidth () {
143
+ void testVariableElementWidthOutputDoesntFitWidth () {
146
144
new AssertBuilder ()
147
145
.withParams (20 , Integer .MAX_VALUE )
148
146
.withArrays (
@@ -158,7 +156,7 @@ public void testVariableElementWidthOutputDoesntFitWidth() {
158
156
}
159
157
160
158
@ Test
161
- public void testContextBefore () {
159
+ void testContextBefore () {
162
160
new AssertBuilder ()
163
161
.withParams (20 , 2 )
164
162
.withArrays (
@@ -174,7 +172,7 @@ public void testContextBefore() {
174
172
}
175
173
176
174
@ Test
177
- public void testBoundedBytesWithDifferentWidth () {
175
+ void testBoundedBytesWithDifferentWidth () {
178
176
new AssertBuilder ()
179
177
.withParams (24 , 2 )
180
178
.withArrays (
@@ -190,7 +188,7 @@ public void testBoundedBytesWithDifferentWidth() {
190
188
}
191
189
192
190
@ Test
193
- public void testBoundedFirstElementIsWrong () {
191
+ void testBoundedFirstElementIsWrong () {
194
192
new AssertBuilder ()
195
193
.withParams (25 , 2 )
196
194
.withArrays (
@@ -206,7 +204,7 @@ public void testBoundedFirstElementIsWrong() {
206
204
}
207
205
208
206
@ Test
209
- public void testBoundedOneArchiveIsEmpty () {
207
+ void testBoundedOneArchiveIsEmpty () {
210
208
new AssertBuilder ()
211
209
.withParams (10 , 2 )
212
210
.withArrays (
@@ -222,7 +220,7 @@ public void testBoundedOneArchiveIsEmpty() {
222
220
}
223
221
224
222
@ Test
225
- public void testUnboundedOneArchiveIsEmpty () {
223
+ void testUnboundedOneArchiveIsEmpty () {
226
224
new AssertBuilder ()
227
225
.withDefaultParams ()
228
226
.withArrays (
@@ -238,7 +236,7 @@ public void testUnboundedOneArchiveIsEmpty() {
238
236
}
239
237
240
238
@ Test
241
- public void testUnprintableCharFormatting () {
239
+ void testUnprintableCharFormatting () {
242
240
new AssertBuilder ()
243
241
.withDefaultParams ()
244
242
.withArrays (
@@ -254,7 +252,7 @@ public void testUnprintableCharFormatting() {
254
252
}
255
253
256
254
@ Test
257
- public void testStringElements () {
255
+ void testStringElements () {
258
256
new AssertBuilder ()
259
257
.withDefaultParams ()
260
258
.withArrays (
@@ -270,7 +268,7 @@ public void testStringElements() {
270
268
}
271
269
272
270
@ Test
273
- public void testToStringableObjects () {
271
+ void testToStringableObjects () {
274
272
class StrObj {
275
273
private final String value ;
276
274
public boolean equals (Object another ) { return ((StrObj )another ).value .equals (value ); }
@@ -294,7 +292,7 @@ class StrObj {
294
292
}
295
293
296
294
@ Test
297
- public void testNullElements () {
295
+ void testNullElements () {
298
296
new AssertBuilder ()
299
297
.withDefaultParams ()
300
298
.withArrays (
@@ -309,14 +307,14 @@ public void testNullElements() {
309
307
.assertTwoWay ();
310
308
}
311
309
312
- @ Test ( expectedExceptions = NullPointerException . class )
313
- public void testFirstArrayIsNull () {
314
- var diff = ArrayDiff .of (null , new String [] {"a" , "b" });
310
+ @ Test
311
+ void testFirstArrayIsNull () {
312
+ assertThrows ( NullPointerException . class , () -> ArrayDiff .of (null , new String [] {"a" , "b" }) );
315
313
}
316
314
317
- @ Test ( expectedExceptions = NullPointerException . class )
318
- public void testSecondArrayIsNull () {
319
- var diff = ArrayDiff .of (null , new String [] {"a" , "b" });
315
+ @ Test
316
+ void testSecondArrayIsNull () {
317
+ assertThrows ( NullPointerException . class , () -> ArrayDiff .of (new String [] {"a" , "b" }, null ) );
320
318
}
321
319
322
320
class AssertBuilder {
@@ -331,30 +329,30 @@ class AssertBuilder {
331
329
private String secondFormattedArray ;
332
330
private String failureMark ;
333
331
334
- public AssertBuilder withDefaultParams () {
332
+ AssertBuilder withDefaultParams () {
335
333
defaultParameters = true ;
336
334
return this ;
337
335
}
338
336
339
- public AssertBuilder withParams (int width , int contextBefore ) {
337
+ AssertBuilder withParams (int width , int contextBefore ) {
340
338
defaultParameters = false ;
341
339
this .width = width ;
342
340
this .contextBefore = contextBefore ;
343
341
return this ;
344
342
}
345
343
346
- public AssertBuilder withArrays (Object first , Object second ) {
344
+ AssertBuilder withArrays (Object first , Object second ) {
347
345
firstArray = first ;
348
346
secondArray = second ;
349
347
return this ;
350
348
}
351
349
352
- public AssertBuilder thatResultIs (boolean result ) {
350
+ AssertBuilder thatResultIs (boolean result ) {
353
351
expectedResult = result ;
354
352
return this ;
355
353
}
356
354
357
- public AssertBuilder thatFormattedValuesAre (
355
+ AssertBuilder thatFormattedValuesAre (
358
356
int idx , String first , String second , String mark ) {
359
357
expectedIndex = idx ;
360
358
firstFormattedArray = first ;
@@ -363,7 +361,7 @@ public AssertBuilder thatFormattedValuesAre(
363
361
return this ;
364
362
}
365
363
366
- public void assertTwoWay () {
364
+ void assertTwoWay () {
367
365
ArrayDiff <?> diff ;
368
366
369
367
// Direct
@@ -382,7 +380,7 @@ public void assertTwoWay() {
382
380
expectedIndex , firstFormattedArray , secondFormattedArray , failureMark );
383
381
384
382
assertFalse (diff .areEqual ());
385
- assertEquals (diff .format (), expected );
383
+ assertEquals (expected , diff .format ());
386
384
}
387
385
388
386
// Reversed
@@ -401,7 +399,7 @@ public void assertTwoWay() {
401
399
expectedIndex , secondFormattedArray , firstFormattedArray , failureMark );
402
400
403
401
assertFalse (diff .areEqual ());
404
- assertEquals (diff .format (), expected );
402
+ assertEquals (expected , diff .format ());
405
403
}
406
404
}
407
405
0 commit comments