Skip to content

Commit a35e96a

Browse files
Qing Xiaosormuras
authored andcommitted
8313612: Use JUnit in lib-test/jdk tests
Reviewed-by: cstein, asotona
1 parent bee7524 commit a35e96a

File tree

5 files changed

+273
-256
lines changed

5 files changed

+273
-256
lines changed

test/lib-test/jdk/test/lib/format/ArrayDiffTest.java

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
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
@@ -23,30 +23,28 @@
2323

2424
package jdk.test.lib.format;
2525

26-
import org.testng.annotations.Test;
26+
import org.junit.jupiter.api.Test;
2727

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.*;
3129

3230
/*
3331
* @test
3432
* @summary Check ArrayDiff formatting
3533
* @library /test/lib
36-
* @run testng jdk.test.lib.format.ArrayDiffTest
34+
* @run junit jdk.test.lib.format.ArrayDiffTest
3735
*/
38-
public class ArrayDiffTest {
36+
class ArrayDiffTest {
3937

4038
@Test
41-
public void testEqualArrays() {
39+
void testEqualArrays() {
4240
char[] first = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
4341
char[] second = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
4442

4543
assertTrue(ArrayDiff.of(first, second).areEqual());
4644
}
4745

4846
@Test
49-
public void testOutputFitsWidth() {
47+
void testOutputFitsWidth() {
5048
new AssertBuilder()
5149
.withDefaultParams()
5250
.withArrays(
@@ -62,7 +60,7 @@ public void testOutputFitsWidth() {
6260
}
6361

6462
@Test
65-
public void testIntegers() {
63+
void testIntegers() {
6664
new AssertBuilder()
6765
.withDefaultParams()
6866
.withArrays(
@@ -78,7 +76,7 @@ public void testIntegers() {
7876
}
7977

8078
@Test
81-
public void testLongs() {
79+
void testLongs() {
8280
new AssertBuilder()
8381
.withDefaultParams()
8482
.withArrays(
@@ -94,7 +92,7 @@ public void testLongs() {
9492
}
9593

9694
@Test
97-
public void testFirstElementIsWrong() {
95+
void testFirstElementIsWrong() {
9896
new AssertBuilder()
9997
.withDefaultParams()
10098
.withArrays(
@@ -110,7 +108,7 @@ public void testFirstElementIsWrong() {
110108
}
111109

112110
@Test
113-
public void testOneElementIsEmpty() {
111+
void testOneElementIsEmpty() {
114112
new AssertBuilder()
115113
.withDefaultParams()
116114
.withArrays(
@@ -126,7 +124,7 @@ public void testOneElementIsEmpty() {
126124
}
127125

128126
@Test
129-
public void testOutputDoesntFitWidth() {
127+
void testOutputDoesntFitWidth() {
130128
new AssertBuilder()
131129
.withParams(20, Integer.MAX_VALUE)
132130
.withArrays(
@@ -142,7 +140,7 @@ public void testOutputDoesntFitWidth() {
142140
}
143141

144142
@Test
145-
public void testVariableElementWidthOutputDoesntFitWidth() {
143+
void testVariableElementWidthOutputDoesntFitWidth() {
146144
new AssertBuilder()
147145
.withParams(20, Integer.MAX_VALUE)
148146
.withArrays(
@@ -158,7 +156,7 @@ public void testVariableElementWidthOutputDoesntFitWidth() {
158156
}
159157

160158
@Test
161-
public void testContextBefore() {
159+
void testContextBefore() {
162160
new AssertBuilder()
163161
.withParams(20, 2)
164162
.withArrays(
@@ -174,7 +172,7 @@ public void testContextBefore() {
174172
}
175173

176174
@Test
177-
public void testBoundedBytesWithDifferentWidth() {
175+
void testBoundedBytesWithDifferentWidth() {
178176
new AssertBuilder()
179177
.withParams(24, 2)
180178
.withArrays(
@@ -190,7 +188,7 @@ public void testBoundedBytesWithDifferentWidth() {
190188
}
191189

192190
@Test
193-
public void testBoundedFirstElementIsWrong() {
191+
void testBoundedFirstElementIsWrong() {
194192
new AssertBuilder()
195193
.withParams(25, 2)
196194
.withArrays(
@@ -206,7 +204,7 @@ public void testBoundedFirstElementIsWrong() {
206204
}
207205

208206
@Test
209-
public void testBoundedOneArchiveIsEmpty() {
207+
void testBoundedOneArchiveIsEmpty() {
210208
new AssertBuilder()
211209
.withParams(10, 2)
212210
.withArrays(
@@ -222,7 +220,7 @@ public void testBoundedOneArchiveIsEmpty() {
222220
}
223221

224222
@Test
225-
public void testUnboundedOneArchiveIsEmpty() {
223+
void testUnboundedOneArchiveIsEmpty() {
226224
new AssertBuilder()
227225
.withDefaultParams()
228226
.withArrays(
@@ -238,7 +236,7 @@ public void testUnboundedOneArchiveIsEmpty() {
238236
}
239237

240238
@Test
241-
public void testUnprintableCharFormatting() {
239+
void testUnprintableCharFormatting() {
242240
new AssertBuilder()
243241
.withDefaultParams()
244242
.withArrays(
@@ -254,7 +252,7 @@ public void testUnprintableCharFormatting() {
254252
}
255253

256254
@Test
257-
public void testStringElements() {
255+
void testStringElements() {
258256
new AssertBuilder()
259257
.withDefaultParams()
260258
.withArrays(
@@ -270,7 +268,7 @@ public void testStringElements() {
270268
}
271269

272270
@Test
273-
public void testToStringableObjects() {
271+
void testToStringableObjects() {
274272
class StrObj {
275273
private final String value;
276274
public boolean equals(Object another) { return ((StrObj)another).value.equals(value); }
@@ -294,7 +292,7 @@ class StrObj {
294292
}
295293

296294
@Test
297-
public void testNullElements() {
295+
void testNullElements() {
298296
new AssertBuilder()
299297
.withDefaultParams()
300298
.withArrays(
@@ -309,14 +307,14 @@ public void testNullElements() {
309307
.assertTwoWay();
310308
}
311309

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"}));
315313
}
316314

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));
320318
}
321319

322320
class AssertBuilder {
@@ -331,30 +329,30 @@ class AssertBuilder {
331329
private String secondFormattedArray;
332330
private String failureMark;
333331

334-
public AssertBuilder withDefaultParams() {
332+
AssertBuilder withDefaultParams() {
335333
defaultParameters = true;
336334
return this;
337335
}
338336

339-
public AssertBuilder withParams(int width, int contextBefore) {
337+
AssertBuilder withParams(int width, int contextBefore) {
340338
defaultParameters = false;
341339
this.width = width;
342340
this.contextBefore = contextBefore;
343341
return this;
344342
}
345343

346-
public AssertBuilder withArrays(Object first, Object second) {
344+
AssertBuilder withArrays(Object first, Object second) {
347345
firstArray = first;
348346
secondArray = second;
349347
return this;
350348
}
351349

352-
public AssertBuilder thatResultIs(boolean result) {
350+
AssertBuilder thatResultIs(boolean result) {
353351
expectedResult = result;
354352
return this;
355353
}
356354

357-
public AssertBuilder thatFormattedValuesAre(
355+
AssertBuilder thatFormattedValuesAre(
358356
int idx, String first, String second, String mark) {
359357
expectedIndex = idx;
360358
firstFormattedArray = first;
@@ -363,7 +361,7 @@ public AssertBuilder thatFormattedValuesAre(
363361
return this;
364362
}
365363

366-
public void assertTwoWay() {
364+
void assertTwoWay() {
367365
ArrayDiff<?> diff;
368366

369367
// Direct
@@ -382,7 +380,7 @@ public void assertTwoWay() {
382380
expectedIndex, firstFormattedArray, secondFormattedArray, failureMark);
383381

384382
assertFalse(diff.areEqual());
385-
assertEquals(diff.format(), expected);
383+
assertEquals(expected, diff.format());
386384
}
387385

388386
// Reversed
@@ -401,7 +399,7 @@ public void assertTwoWay() {
401399
expectedIndex, secondFormattedArray, firstFormattedArray, failureMark);
402400

403401
assertFalse(diff.areEqual());
404-
assertEquals(diff.format(), expected);
402+
assertEquals(expected, diff.format());
405403
}
406404
}
407405

test/lib-test/jdk/test/lib/hexdump/ASN1FormatterTest.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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
@@ -23,8 +23,7 @@
2323

2424
package jdk.test.lib.hexdump;
2525

26-
import org.testng.Assert;
27-
import org.testng.annotations.Test;
26+
import org.junit.jupiter.api.Test;
2827

2928
import java.io.DataInputStream;
3029
import java.io.EOFException;
@@ -34,22 +33,21 @@
3433
import java.nio.file.Path;
3534
import java.util.Base64;
3635

37-
import static org.testng.Assert.*;
36+
import static org.junit.jupiter.api.Assertions.*;
3837

3938
/*
4039
* @test
4140
* @summary ASN.1 formatting
4241
* @modules java.base/sun.security.util
4342
* @library /test/lib
4443
* @compile ASN1FormatterTest.java
45-
* @run testng jdk.test.lib.hexdump.ASN1FormatterTest
44+
* @run junit jdk.test.lib.hexdump.ASN1FormatterTest
4645
*/
47-
@Test
48-
public class ASN1FormatterTest {
46+
class ASN1FormatterTest {
4947
private static final String DIR = System.getProperty("test.src", ".");
5048

5149
@Test
52-
static void testPEM() throws IOException {
50+
void testPEM() throws IOException {
5351
String certFile = "openssl.p12.pem";
5452
Path certPath = Path.of(DIR, certFile);
5553
System.out.println("certPath: " + certPath);
@@ -64,18 +62,18 @@ static void testPEM() throws IOException {
6462
String result = ASN1Formatter.formatter().annotate(is);
6563
System.out.println(result);
6664

67-
Assert.assertEquals(result.lines().count(), 76, "Lines");
68-
Assert.assertEquals(result.lines().filter(s -> s.contains("SEQUENCE")).count(),24, "Sequences");
69-
Assert.assertEquals(result.lines().filter(s -> s.contains("OBJECT ID")).count(), 17, "ObjectIDs");
70-
Assert.assertEquals(result.lines().filter(s -> s.contains("UTCTIME")).count(), 2, "UTCTIME");
71-
Assert.assertEquals(result.lines().filter(s -> s.contains("BIT STRING")).count(), 3, "BitStrings");
65+
assertEquals(76, result.lines().count(), "Lines");
66+
assertEquals(24, result.lines().filter(s -> s.contains("SEQUENCE")).count(),"Sequences");
67+
assertEquals(17, result.lines().filter(s -> s.contains("OBJECT ID")).count(), "ObjectIDs");
68+
assertEquals(2, result.lines().filter(s -> s.contains("UTCTIME")).count(), "UTCTIME");
69+
assertEquals(3, result.lines().filter(s -> s.contains("BIT STRING")).count(), "BitStrings");
7270
} catch (EOFException eof) {
7371
// done
7472
}
7573
}
7674

7775
@Test
78-
static void dumpPEM() throws IOException {
76+
void dumpPEM() throws IOException {
7977
String file = "openssl.p12.pem";
8078
Path path = Path.of(DIR, file);
8179
System.out.println("path: " + path);
@@ -92,34 +90,34 @@ static void dumpPEM() throws IOException {
9290
String result = p.toString(wis);
9391
System.out.println(result);
9492

95-
Assert.assertEquals(result.lines().count(), 126, "Lines");
96-
Assert.assertEquals(result.lines().filter(s -> s.contains("SEQUENCE")).count(), 24, "Sequences");
97-
Assert.assertEquals(result.lines().filter(s -> s.contains("OBJECT ID")).count(), 17, "ObjectIDs");
98-
Assert.assertEquals(result.lines().filter(s -> s.contains("UTCTIME")).count(), 2, "UTCTIME");
99-
Assert.assertEquals(result.lines().filter(s -> s.contains("BIT STRING")).count(), 3, "BitStrings");
93+
assertEquals(126, result.lines().count(), "Lines");
94+
assertEquals(24, result.lines().filter(s -> s.contains("SEQUENCE")).count(), "Sequences");
95+
assertEquals(17, result.lines().filter(s -> s.contains("OBJECT ID")).count(), "ObjectIDs");
96+
assertEquals(2, result.lines().filter(s -> s.contains("UTCTIME")).count(), "UTCTIME");
97+
assertEquals(3, result.lines().filter(s -> s.contains("BIT STRING")).count(), "BitStrings");
10098
} catch (EOFException eof) {
10199
// done
102100
}
103101
}
104102

105103
@Test
106-
static void testIndefinite() {
104+
void testIndefinite() {
107105
byte[] bytes = {0x24, (byte) 0x80, 4, 2, 'a', 'b', 4, 2, 'c', 'd', 0, 0};
108106
HexPrinter p = HexPrinter.simple()
109107
.formatter(ASN1Formatter.formatter(), "; ", 100);
110108
String result = p.toString(bytes);
111109
System.out.println(result);
112110

113-
Assert.assertEquals(result.lines().filter(s -> s.contains("OCTET STRING [INDEFINITE]")).count(),
114-
1, "Indefinite length");
115-
Assert.assertEquals(result.lines().filter(s -> s.contains("; OCTET STRING [2]")).count(),
116-
2, "Octet Sequences");
117-
Assert.assertEquals(result.lines().filter(s -> s.contains("; END-OF-CONTENT")).count(),
118-
1, "end of content");
111+
assertEquals(1, result.lines().filter(s -> s.contains("OCTET STRING [INDEFINITE]")).count(),
112+
"Indefinite length");
113+
assertEquals(2, result.lines().filter(s -> s.contains("; OCTET STRING [2]")).count(),
114+
"Octet Sequences");
115+
assertEquals(1, result.lines().filter(s -> s.contains("; END-OF-CONTENT")).count(),
116+
"end of content");
119117
}
120118

121119
@Test
122-
static void testMain() {
120+
void testMain() {
123121
String file = "openssl.p12.pem";
124122
Path path = Path.of(DIR, file);
125123
String[] args = { path.toString() };

0 commit comments

Comments
 (0)