Skip to content

Commit 3e04da1

Browse files
committed
8365776: Convert JShell tests to use JUnit instead of TestNG
Reviewed-by: mdoerr Backport-of: b0ca9bf
1 parent 4d0a11b commit 3e04da1

122 files changed

Lines changed: 1550 additions & 1030 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/langtools/jdk/jshell/AbstractStopExecutionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import jdk.jshell.JShell;
2828

29-
import static org.testng.Assert.fail;
29+
import static org.junit.jupiter.api.Assertions.fail;
3030

3131
public abstract class AbstractStopExecutionTest extends KullaTesting {
3232

test/langtools/jdk/jshell/AnalysisTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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,14 @@
2525
* @test
2626
* @summary Test SourceCodeAnalysis
2727
* @build KullaTesting TestingInputStream
28-
* @run testng AnalysisTest
28+
* @run junit AnalysisTest
2929
*/
3030

31-
import org.testng.annotations.Test;
31+
import org.junit.jupiter.api.Test;
3232

33-
@Test
3433
public class AnalysisTest extends KullaTesting {
3534

35+
@Test
3636
public void testSource() {
3737
assertAnalyze("int x=3//test", "int x=3;//test", "", true);
3838
assertAnalyze("int x=3 ;//test", "int x=3 ;//test", "", true);
@@ -41,6 +41,7 @@ public void testSource() {
4141
assertAnalyze("int ff; int v // hi", "int ff;", " int v // hi", true);
4242
}
4343

44+
@Test
4445
public void testSourceSlashStar() {
4546
assertAnalyze("/*zoo*/int x=3 /*test*/", "/*zoo*/int x=3; /*test*/", "", true);
4647
assertAnalyze("/*zoo*/int x=3 ;/*test*/", "/*zoo*/int x=3 ;/*test*/", "", true);
@@ -49,11 +50,13 @@ public void testSourceSlashStar() {
4950
assertAnalyze("int ff; int v /*hgjghj*/", "int ff;", " int v /*hgjghj*/", true);
5051
}
5152

53+
@Test
5254
public void testIncomplete() {
5355
assertAnalyze("void m() { //erer", null, "void m() { //erer\n", false);
5456
assertAnalyze("int m=//", null, "int m=//\n", false);
5557
}
5658

59+
@Test
5760
public void testExpression() {
5861
assertAnalyze("45//test", "45//test", "", true);
5962
assertAnalyze("45;//test", "45;//test", "", true);

test/langtools/jdk/jshell/AnalyzeSnippetTest.java

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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,7 +26,7 @@
2626
* @bug 8182270 8341176
2727
* @summary test non-eval Snippet analysis
2828
* @build KullaTesting TestingInputStream
29-
* @run testng AnalyzeSnippetTest
29+
* @run junit AnalyzeSnippetTest
3030
*/
3131

3232
import java.io.ByteArrayOutputStream;
@@ -36,15 +36,12 @@
3636
import jdk.jshell.Snippet;
3737
import jdk.jshell.DeclarationSnippet;
3838
import jdk.jshell.Diag;
39-
import org.testng.annotations.Test;
4039

4140
import jdk.jshell.JShell;
4241
import jdk.jshell.MethodSnippet;
43-
import static org.testng.Assert.assertFalse;
44-
import static org.testng.Assert.assertTrue;
45-
import static org.testng.Assert.assertEquals;
46-
import org.testng.annotations.AfterMethod;
47-
import org.testng.annotations.BeforeMethod;
42+
import static org.junit.jupiter.api.Assertions.assertFalse;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.junit.jupiter.api.Assertions.assertEquals;
4845
import jdk.jshell.ErroneousSnippet;
4946
import jdk.jshell.ExpressionSnippet;
5047
import jdk.jshell.ImportSnippet;
@@ -55,14 +52,16 @@
5552
import jdk.jshell.VarSnippet;
5653
import static jdk.jshell.Snippet.SubKind.*;
5754
import jdk.jshell.SourceCodeAnalysis.SnippetWrapper;
55+
import org.junit.jupiter.api.AfterEach;
56+
import org.junit.jupiter.api.BeforeEach;
57+
import org.junit.jupiter.api.Test;
5858

59-
@Test
6059
public class AnalyzeSnippetTest {
6160

6261
JShell state;
6362
SourceCodeAnalysis sca;
6463

65-
@BeforeMethod
64+
@BeforeEach
6665
public void setUp() {
6766
state = JShell.builder()
6867
.out(new PrintStream(new ByteArrayOutputStream()))
@@ -72,7 +71,7 @@ public void setUp() {
7271
sca = state.sourceCodeAnalysis();
7372
}
7473

75-
@AfterMethod
74+
@AfterEach
7675
public void tearDown() {
7776
if (state != null) {
7877
state.close();
@@ -81,69 +80,77 @@ public void tearDown() {
8180
sca = null;
8281
}
8382

83+
@Test
8484
public void testImport() {
8585
ImportSnippet sn = (ImportSnippet) assertSnippet("import java.util.List;",
8686
SubKind.SINGLE_TYPE_IMPORT_SUBKIND);
87-
assertEquals(sn.name(), "List");
87+
assertEquals("List", sn.name());
8888
sn = (ImportSnippet) assertSnippet("import static java.nio.file.StandardOpenOption.CREATE;",
8989
SubKind.SINGLE_STATIC_IMPORT_SUBKIND);
9090
assertTrue(sn.isStatic());
9191
}
9292

93+
@Test
9394
public void testClass() {
9495
TypeDeclSnippet sn = (TypeDeclSnippet) assertSnippet("class C {}",
9596
SubKind.CLASS_SUBKIND);
96-
assertEquals(sn.name(), "C");
97+
assertEquals("C", sn.name());
9798
sn = (TypeDeclSnippet) assertSnippet("enum EE {A, B , C}",
9899
SubKind.ENUM_SUBKIND);
99100
}
100101

102+
@Test
101103
public void testMethod() {
102104
MethodSnippet sn = (MethodSnippet) assertSnippet("int m(int x) { return x + x; }",
103105
SubKind.METHOD_SUBKIND);
104-
assertEquals(sn.name(), "m");
105-
assertEquals(sn.signature(), "(int)int");
106+
assertEquals("m", sn.name());
107+
assertEquals("(int)int", sn.signature());
106108
}
107109

110+
@Test
108111
public void testVar() {
109112
VarSnippet sn = (VarSnippet) assertSnippet("int i;",
110113
SubKind.VAR_DECLARATION_SUBKIND);
111-
assertEquals(sn.name(), "i");
112-
assertEquals(sn.typeName(), "int");
114+
assertEquals("i", sn.name());
115+
assertEquals("int", sn.typeName());
113116
sn = (VarSnippet) assertSnippet("int jj = 6;",
114117
SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND);
115118
sn = (VarSnippet) assertSnippet("2 + 2",
116119
SubKind.TEMP_VAR_EXPRESSION_SUBKIND);
117120
}
118121

122+
@Test
119123
public void testExpression() {
120124
state.eval("int aa = 10;");
121125
ExpressionSnippet sn = (ExpressionSnippet) assertSnippet("aa",
122126
SubKind.VAR_VALUE_SUBKIND);
123-
assertEquals(sn.name(), "aa");
124-
assertEquals(sn.typeName(), "int");
127+
assertEquals("aa", sn.name());
128+
assertEquals("int", sn.typeName());
125129
sn = (ExpressionSnippet) assertSnippet("aa;",
126130
SubKind.VAR_VALUE_SUBKIND);
127-
assertEquals(sn.name(), "aa");
128-
assertEquals(sn.typeName(), "int");
131+
assertEquals("aa", sn.name());
132+
assertEquals("int", sn.typeName());
129133
sn = (ExpressionSnippet) assertSnippet("aa = 99",
130134
SubKind.ASSIGNMENT_SUBKIND);
131135
}
132136

137+
@Test
133138
public void testStatement() {
134139
StatementSnippet sn = (StatementSnippet) assertSnippet("System.out.println(33)",
135140
SubKind.STATEMENT_SUBKIND);
136141
sn = (StatementSnippet) assertSnippet("if (true) System.out.println(33);",
137142
SubKind.STATEMENT_SUBKIND);
138143
}
139144

145+
@Test
140146
public void testErroneous() {
141147
ErroneousSnippet sn = (ErroneousSnippet) assertSnippet("+++",
142148
SubKind.UNKNOWN_SUBKIND);
143149
sn = (ErroneousSnippet) assertSnippet("abc",
144150
SubKind.UNKNOWN_SUBKIND);
145151
}
146152

153+
@Test
147154
public void testDiagnosticsForSourceSnippet() {
148155
Snippet sn;
149156
sn = assertSnippet("unknown()", UNKNOWN_SUBKIND);
@@ -164,45 +171,47 @@ public void testDiagnosticsForSourceSnippet() {
164171
assertDiagnostics(sn, "7-22:compiler.err.doesnt.exist");
165172
}
166173

174+
@Test
167175
public void testSnippetWrapper() {
168176
SourceCodeAnalysis analysis = state.sourceCodeAnalysis();
169177
Snippet sn;
170178
String code = "unknown()";
171179
sn = assertSnippet(code, UNKNOWN_SUBKIND);
172180
SnippetWrapper wrapper = analysis.wrapper(sn);
173181
String wrapped = wrapper.wrapped();
174-
assertEquals(wrapped, """
175-
package REPL;
176-
177-
class $JShell$DOESNOTMATTER {
178-
public static java.lang.Object do_it$() throws java.lang.Throwable {
179-
return unknown();
180-
}
181-
}
182-
""");
182+
assertEquals("""
183+
package REPL;
184+
185+
class $JShell$DOESNOTMATTER {
186+
public static java.lang.Object do_it$() throws java.lang.Throwable {
187+
return unknown();
188+
}
189+
}
190+
""", wrapped);
183191
for (int pos = 0; pos < code.length(); pos++) {
184192
int wrappedPos = wrapper.sourceToWrappedPosition(pos);
185-
assertEquals(wrapped.charAt(wrappedPos), code.charAt(pos));
186-
assertEquals(wrapper.wrappedToSourcePosition(wrappedPos), pos);
193+
assertEquals(code.charAt(pos), wrapped.charAt(wrappedPos));
194+
assertEquals(pos, wrapper.wrappedToSourcePosition(wrappedPos));
187195
}
188196
}
189197

198+
@Test
190199
public void testNoStateChange() {
191200
assertSnippet("int a = 5;", SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND);
192201
assertSnippet("a", SubKind.UNKNOWN_SUBKIND);
193202
VarSnippet vsn = (VarSnippet) state.eval("int aa = 10;").get(0).snippet();
194203
assertSnippet("++aa;", SubKind.TEMP_VAR_EXPRESSION_SUBKIND);
195-
assertEquals(state.varValue(vsn), "10");
204+
assertEquals("10", state.varValue(vsn));
196205
assertSnippet("class CC {}", SubKind.CLASS_SUBKIND);
197206
assertSnippet("new CC();", SubKind.UNKNOWN_SUBKIND);
198207
}
199208

200209
private Snippet assertSnippet(String input, SubKind sk) {
201210
List<Snippet> sns = sca.sourceToSnippets(input);
202-
assertEquals(sns.size(), 1, "snippet count");
211+
assertEquals(1, sns.size(), "snippet count");
203212
Snippet sn = sns.get(0);
204-
assertEquals(sn.id(), "*UNASSOCIATED*");
205-
assertEquals(sn.subKind(), sk);
213+
assertEquals("*UNASSOCIATED*", sn.id());
214+
assertEquals(sk, sn.subKind());
206215
return sn;
207216
}
208217

@@ -213,6 +222,6 @@ private String diagToString(Diag d) {
213222
private void assertDiagnostics(Snippet s, String... expectedDiags) {
214223
List<String> actual = state.diagnostics(s).map(this::diagToString).toList();
215224
List<String> expected = List.of(expectedDiags);
216-
assertEquals(actual, expected);
225+
assertEquals(expected, actual);
217226
}
218227
}

test/langtools/jdk/jshell/BadExecutionControlSpecTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 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
@@ -29,7 +29,7 @@
2929
* jdk.compiler/com.sun.tools.javac.main
3030
* jdk.jdeps/com.sun.tools.javap
3131
* jdk.jshell/jdk.internal.jshell.tool
32-
* @run testng BadExecutionControlSpecTest
32+
* @run junit BadExecutionControlSpecTest
3333
*/
3434

3535
import java.io.ByteArrayInputStream;
@@ -38,12 +38,11 @@
3838
import java.io.PrintStream;
3939
import java.util.Collections;
4040
import java.util.List;
41-
import org.testng.annotations.Test;
4241
import jdk.jshell.spi.ExecutionControl;
4342
import jdk.jshell.spi.ExecutionEnv;
44-
import static org.testng.Assert.fail;
43+
import static org.junit.jupiter.api.Assertions.fail;
44+
import org.junit.jupiter.api.Test;
4545

46-
@Test
4746
public class BadExecutionControlSpecTest {
4847
private static void assertIllegal(String spec) throws Throwable {
4948
try {
@@ -80,13 +79,15 @@ public void closeDown() {
8079
}
8180
}
8281

82+
@Test
8383
public void syntaxTest() throws Throwable {
8484
assertIllegal(":launch(true)");
8585
assertIllegal("jdi:launch(true");
8686
assertIllegal("jdi:launch(true)$");
8787
assertIllegal("jdi:,");
8888
}
8989

90+
@Test
9091
public void notFoundTest() throws Throwable {
9192
assertIllegal("fruitbats");
9293
assertIllegal("jdi:baz(true)");

0 commit comments

Comments
 (0)