Skip to content

Commit 682fd78

Browse files
committed
8366678: Use JUnit in test/langtools/tools/javac
Reviewed-by: liach
1 parent 5efaa99 commit 682fd78

39 files changed

Lines changed: 556 additions & 458 deletions

test/langtools/tools/javac/file/FSInfoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 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
@@ -23,22 +23,22 @@
2323

2424
import com.sun.tools.javac.file.FSInfo;
2525
import com.sun.tools.javac.util.Context;
26-
import org.testng.annotations.Test;
2726

2827
import java.io.IOException;
2928
import java.nio.file.Files;
3029
import java.nio.file.Path;
3130
import java.util.Locale;
3231
import java.util.jar.JarOutputStream;
3332
import java.util.jar.Manifest;
33+
import org.junit.jupiter.api.Test;
3434

3535
/*
3636
* @test
3737
* @bug 8232170
3838
* @summary Test com.sun.tools.javac.file.FSInfo
3939
* @modules jdk.compiler/com.sun.tools.javac.util
4040
* jdk.compiler/com.sun.tools.javac.file
41-
* @run testng FSInfoTest
41+
* @run junit FSInfoTest
4242
*/
4343
public class FSInfoTest {
4444

test/langtools/tools/javac/file/MultiReleaseJar/MultiReleaseJarAwareSJFM.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 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
@@ -30,14 +30,9 @@
3030
* @modules jdk.compiler/com.sun.tools.javac.api
3131
* jdk.compiler/com.sun.tools.javac.main
3232
* @build toolbox.ToolBox
33-
* @run testng MultiReleaseJarAwareSJFM
33+
* @run junit MultiReleaseJarAwareSJFM
3434
*/
3535

36-
import org.testng.Assert;
37-
import org.testng.annotations.AfterClass;
38-
import org.testng.annotations.BeforeClass;
39-
import org.testng.annotations.DataProvider;
40-
import org.testng.annotations.Test;
4136

4237
import javax.tools.FileObject;
4338
import javax.tools.JavaFileManager;
@@ -50,11 +45,18 @@
5045
import java.lang.invoke.MethodHandles;
5146
import java.lang.invoke.MethodType;
5247
import java.util.List;
48+
import org.junit.jupiter.api.AfterAll;
49+
import org.junit.jupiter.api.Assertions;
50+
import org.junit.jupiter.api.BeforeAll;
51+
import org.junit.jupiter.api.TestInstance;
52+
import org.junit.jupiter.params.ParameterizedTest;
53+
import org.junit.jupiter.params.provider.MethodSource;
5354

5455
import toolbox.JarTask;
5556
import toolbox.JavacTask;
5657
import toolbox.ToolBox;
5758

59+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
5860
public class MultiReleaseJarAwareSJFM {
5961
private static final int CURRENT_VERSION = Runtime.version().major();
6062

@@ -113,7 +115,7 @@ public boolean isOutputLocation() {
113115
}
114116
};
115117

116-
@BeforeClass
118+
@BeforeAll
117119
public void setup() throws Exception {
118120
tb.createDirectories("classes",
119121
"classes/META-INF/versions/9",
@@ -140,7 +142,7 @@ public void setup() throws Exception {
140142
.run();
141143
}
142144

143-
@AfterClass
145+
@AfterAll
144146
public void teardown() throws Exception {
145147
tb.deleteFiles(
146148
"classes/META-INF/versions/" + CURRENT_VERSION + "/version/Version.class",
@@ -159,7 +161,6 @@ public void teardown() throws Exception {
159161
);
160162
}
161163

162-
@DataProvider(name = "versions")
163164
public Object[][] data() {
164165
return new Object[][] {
165166
{"", 8},
@@ -169,7 +170,8 @@ public Object[][] data() {
169170
};
170171
}
171172

172-
@Test(dataProvider = "versions")
173+
@ParameterizedTest
174+
@MethodSource("data")
173175
public void test(String version, int expected) throws Throwable {
174176
StandardJavaFileManager jfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
175177
jfm.setLocation(jloc, List.of(new File("multi-release.jar")));
@@ -183,7 +185,7 @@ public void test(String version, int expected) throws Throwable {
183185
MethodType mt = MethodType.methodType(int.class);
184186
MethodHandle mh = MethodHandles.lookup().findVirtual(versionClass, "getVersion", mt);
185187
int v = (int)mh.invoke(versionClass.newInstance());
186-
Assert.assertEquals(v, expected);
188+
Assertions.assertEquals(expected, v);
187189

188190
jfm.close();
189191
}

test/langtools/tools/javac/file/MultiReleaseJar/MultiReleaseJarTest.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@
3030
* @modules jdk.compiler/com.sun.tools.javac.api
3131
* jdk.compiler/com.sun.tools.javac.main
3232
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
33-
* @run testng/timeout=480 MultiReleaseJarTest
33+
* @run junit/timeout=480 MultiReleaseJarTest
3434
*/
3535

36-
import org.testng.annotations.AfterClass;
37-
import org.testng.annotations.BeforeClass;
38-
import org.testng.annotations.DataProvider;
39-
import org.testng.annotations.Test;
36+
import org.junit.jupiter.api.AfterAll;
37+
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.TestInstance;
39+
import org.junit.jupiter.params.ParameterizedTest;
40+
import org.junit.jupiter.params.provider.MethodSource;
4041

4142
import toolbox.JarTask;
4243
import toolbox.JavacTask;
4344
import toolbox.Task;
4445
import toolbox.ToolBox;
4546

4647

48+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4749
public class MultiReleaseJarTest {
4850

4951
private final String main1 =
@@ -84,7 +86,7 @@ public class MultiReleaseJarTest {
8486

8587
private final ToolBox tb = new ToolBox();
8688

87-
@BeforeClass
89+
@BeforeAll
8890
public void setup() throws Exception {
8991
tb.createDirectories("classes", "classes/META-INF/versions/9");
9092
new JavacTask(tb)
@@ -111,7 +113,7 @@ public void setup() throws Exception {
111113
);
112114
}
113115

114-
@AfterClass
116+
@AfterAll
115117
public void teardown() throws Exception {
116118
tb.deleteFiles(
117119
"multi-release.jar",
@@ -120,8 +122,9 @@ public void teardown() throws Exception {
120122
);
121123
}
122124

123-
@Test(dataProvider="modes")
125+
@ParameterizedTest
124126
// javac -d classes -cp multi-release.jar Main.java -> fails
127+
@MethodSource("createModes")
125128
public void main1Runtime(Task.Mode mode) throws Exception {
126129
tb.writeFile("Main.java", main1);
127130
Task.Result result = new JavacTask(tb, mode)
@@ -134,8 +137,9 @@ public void main1Runtime(Task.Mode mode) throws Exception {
134137

135138
}
136139

137-
@Test(dataProvider="modes")
140+
@ParameterizedTest
138141
// javac -d classes --release 8 -cp multi-release.jar Main.java -> succeeds
142+
@MethodSource("createModes")
139143
public void main1Release8(Task.Mode mode) throws Exception {
140144
tb.writeFile("Main.java", main1);
141145
Task.Result result = new JavacTask(tb, mode)
@@ -148,8 +152,9 @@ public void main1Release8(Task.Mode mode) throws Exception {
148152
tb.deleteFiles("Main.java");
149153
}
150154

151-
@Test(dataProvider="modes")
155+
@ParameterizedTest
152156
// javac -d classes --release 9 -cp multi-release.jar Main.java -> fails
157+
@MethodSource("createModes")
153158
public void main1Release9(Task.Mode mode) throws Exception {
154159
tb.writeFile("Main.java", main1);
155160
Task.Result result = new JavacTask(tb, mode)
@@ -162,8 +167,9 @@ public void main1Release9(Task.Mode mode) throws Exception {
162167
tb.deleteFiles("Main.java");
163168
}
164169

165-
@Test(dataProvider="modes")
170+
@ParameterizedTest
166171
// javac -d classes -cp multi-release.jar Main.java -> succeeds
172+
@MethodSource("createModes")
167173
public void main2Runtime(Task.Mode mode) throws Exception {
168174
tb.writeFile("Main.java", main2);
169175
Task.Result result = new JavacTask(tb, mode)
@@ -176,8 +182,9 @@ public void main2Runtime(Task.Mode mode) throws Exception {
176182

177183
}
178184

179-
@Test(dataProvider="modes")
185+
@ParameterizedTest
180186
// javac -d classes --release 8 -cp multi-release.jar Main.java -> fails
187+
@MethodSource("createModes")
181188
public void main2Release8(Task.Mode mode) throws Exception {
182189
tb.writeFile("Main.java", main2);
183190
Task.Result result = new JavacTask(tb, mode)
@@ -190,8 +197,9 @@ public void main2Release8(Task.Mode mode) throws Exception {
190197
tb.deleteFiles("Main.java");
191198
}
192199

193-
@Test(dataProvider="modes")
200+
@ParameterizedTest
194201
// javac -d classes --release 9 -cp multi-release.jar Main.java -> succeeds
202+
@MethodSource("createModes")
195203
public void main2Release9(Task.Mode mode) throws Exception {
196204
tb.writeFile("Main.java", main2);
197205
Task.Result result = new JavacTask(tb, mode)
@@ -204,7 +212,6 @@ public void main2Release9(Task.Mode mode) throws Exception {
204212
tb.deleteFiles("Main.java");
205213
}
206214

207-
@DataProvider(name="modes")
208215
public Object[][] createModes() {
209216
return new Object[][] {
210217
new Object[] {Task.Mode.API},

test/langtools/tools/javac/lambda/lambdaExecution/InInterface.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -25,11 +25,11 @@
2525
* @test
2626
* @bug 8003639
2727
* @summary convert lambda testng tests to jtreg and add them
28-
* @run testng InInterface
28+
* @run junit InInterface
2929
*/
3030

31-
import static org.testng.Assert.assertEquals;
32-
import org.testng.annotations.Test;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import org.junit.jupiter.api.Test;
3333

3434
interface LTII {
3535

@@ -51,12 +51,12 @@ default ILsp2 t2() {
5151

5252
}
5353

54-
@Test
5554
public class InInterface implements LTII {
5655

56+
@Test
5757
public void testLambdaInDefaultMethod() {
58-
assertEquals(t1().m(), "yo");
59-
assertEquals(t2().m("p"), "snurp");
58+
assertEquals("yo", t1().m());
59+
assertEquals("snurp", t2().m("p"));
6060
}
6161

6262
}

test/langtools/tools/javac/lambda/lambdaExecution/InnerConstructor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -25,18 +25,18 @@
2525
* @test
2626
* @bug 8003639
2727
* @summary convert lambda testng tests to jtreg and add them
28-
* @run testng InnerConstructor
28+
* @run junit InnerConstructor
2929
*/
3030

31-
import static org.testng.Assert.assertEquals;
32-
import org.testng.annotations.Test;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import org.junit.jupiter.api.Test;
3333

34-
@Test
3534
public class InnerConstructor {
3635

36+
@Test
3737
public void testLambdaWithInnerConstructor() {
38-
assertEquals(seq1().m().toString(), "Cbl:nada");
39-
assertEquals(seq2().m("rats").toString(), "Cbl:rats");
38+
assertEquals("Cbl:nada", seq1().m().toString());
39+
assertEquals("Cbl:rats", seq2().m("rats").toString());
4040
}
4141

4242
Ib1 seq1() {

test/langtools/tools/javac/lambda/lambdaExecution/LambdaTranslationTest1.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -25,14 +25,12 @@
2525
* @test
2626
* @bug 8003639
2727
* @summary convert lambda testng tests to jtreg and add them
28-
* @run testng/othervm -Duser.language=en -Duser.country=US LambdaTranslationTest1
28+
* @run junit/othervm -Duser.language=en -Duser.country=US LambdaTranslationTest1
2929
*/
3030

31-
import org.testng.annotations.Test;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import org.junit.jupiter.api.Test;
3233

33-
import static org.testng.Assert.assertEquals;
34-
35-
@Test
3634
public class LambdaTranslationTest1 extends LT1Sub {
3735

3836
String cntxt = "blah";
@@ -43,7 +41,7 @@ public class LambdaTranslationTest1 extends LT1Sub {
4341
private static void appendResult(Object s) { result.set(result.get().toString() + s); }
4442

4543
private static void assertResult(String expected) {
46-
assertEquals(result.get().toString(), expected);
44+
assertEquals(expected, result.get().toString());
4745
}
4846

4947
static Integer count(String s) {
@@ -66,6 +64,7 @@ static void deye(double d) {
6664
setResult(String.format("d:%f", d));
6765
}
6866

67+
@Test
6968
public void testLambdas() {
7069
TBlock<Object> b = t -> {setResult("Sink0::" + t);};
7170
b.apply("Howdy");
@@ -127,6 +126,7 @@ String get() {
127126
assertResult("b11: *999*");
128127
}
129128

129+
@Test
130130
public void testMethodRefs() {
131131
LT1IA ia = LambdaTranslationTest1::eye;
132132
ia.doit(1234);
@@ -147,6 +147,7 @@ public void testMethodRefs() {
147147
assertEquals((Integer) 6, a.doit("shower"));
148148
}
149149

150+
@Test
150151
public void testInner() throws Exception {
151152
(new In()).doInner();
152153
}

0 commit comments

Comments
 (0)