Skip to content

Commit ae33518

Browse files
committed
Other Rhino module Junit5 conversion
1 parent a91087d commit ae33518

7 files changed

Lines changed: 43 additions & 67 deletions

File tree

rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/BuiltinsTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.mozilla.javascript.tests.scriptengine;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
44

55
import java.io.ByteArrayOutputStream;
66
import java.io.PrintStream;
@@ -10,7 +10,9 @@
1010
import javax.script.ScriptEngineManager;
1111
import javax.script.ScriptException;
1212
import javax.script.SimpleScriptContext;
13-
import org.junit.*;
13+
import org.junit.jupiter.api.Assertions;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.BeforeEach;
1416
import org.mozilla.javascript.engine.RhinoScriptEngineFactory;
1517

1618
public class BuiltinsTest {
@@ -19,23 +21,23 @@ public class BuiltinsTest {
1921

2022
private ScriptEngine engine;
2123

22-
@BeforeClass
24+
@BeforeAll
2325
public static void init() {
2426
manager = new ScriptEngineManager();
2527
manager.registerEngineName("rhino", new RhinoScriptEngineFactory());
2628
}
2729

28-
@Before
30+
@BeforeEach
2931
public void setup() {
3032
engine = manager.getEngineByName("rhino");
3133
}
3234

33-
@Test
35+
@org.junit.jupiter.api.Test
3436
public void printStdout() throws ScriptException {
3537
engine.eval("print('Hello, World!');");
3638
}
3739

38-
@Test
40+
@org.junit.jupiter.api.Test
3941
public void printStdoutAndCheckItPrints() throws Exception {
4042
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
4143
PrintStream original = System.out;
@@ -49,7 +51,7 @@ public void printStdoutAndCheckItPrints() throws Exception {
4951
engine.eval("print('Hello, World!');", sc);
5052

5153
// this has been hard work https://github.com/mozilla/rhino/issues/1356
52-
Assert.assertEquals("Hello, World!\n", bos.toString());
54+
Assertions.assertEquals("Hello, World!\n", bos.toString());
5355
} finally {
5456
// revert the sys out
5557
System.setOut(original);
@@ -58,7 +60,7 @@ public void printStdoutAndCheckItPrints() throws Exception {
5860
}
5961
}
6062

61-
@Test
63+
@org.junit.jupiter.api.Test
6264
public void printWriter() throws ScriptException {
6365
StringWriter sw = new StringWriter();
6466
ScriptContext sc = new SimpleScriptContext();
@@ -67,7 +69,7 @@ public void printWriter() throws ScriptException {
6769
assertEquals(sw.toString(), "one2true\n");
6870
}
6971

70-
@Test
72+
@org.junit.jupiter.api.Test
7173
public void printWriterGeneric() throws ScriptException {
7274
StringWriter sw = new StringWriter();
7375
engine.getContext().setWriter(sw);

rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/FactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.mozilla.javascript.tests.scriptengine;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
44

55
import javax.script.ScriptEngine;
66
import javax.script.ScriptEngineFactory;
77
import javax.script.ScriptEngineManager;
8-
import org.junit.Test;
8+
import org.junit.jupiter.api.Test;
99
import org.mozilla.javascript.engine.RhinoScriptEngine;
1010
import org.mozilla.javascript.engine.RhinoScriptEngineFactory;
1111

rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/InvocableTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package org.mozilla.javascript.tests.scriptengine;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
5-
import static org.junit.Assert.assertNull;
6-
import static org.junit.Assert.assertThrows;
3+
import static org.junit.jupiter.api.Assertions.*;
74

85
import java.io.FileReader;
96
import javax.script.Invocable;
107
import javax.script.ScriptEngine;
118
import javax.script.ScriptEngineManager;
129
import javax.script.ScriptException;
13-
import org.junit.Before;
14-
import org.junit.BeforeClass;
15-
import org.junit.Test;
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
1613
import org.mozilla.javascript.engine.RhinoScriptEngineFactory;
1714

1815
public class InvocableTest {
@@ -22,13 +19,13 @@ public class InvocableTest {
2219
private ScriptEngine engine;
2320
private Invocable iEngine;
2421

25-
@BeforeClass
22+
@BeforeAll
2623
public static void init() {
2724
manager = new ScriptEngineManager();
2825
manager.registerEngineName("rhino", new RhinoScriptEngineFactory());
2926
}
3027

31-
@Before
28+
@BeforeEach
3229
public void setup() {
3330
engine = manager.getEngineByName("rhino");
3431
iEngine = (Invocable) engine;
@@ -144,11 +141,7 @@ public void interfaceMethodMissingTest() throws ScriptException {
144141

145142
@Test
146143
public void invokeNotFoundTest() {
147-
assertThrows(
148-
NoSuchMethodException.class,
149-
() -> {
150-
iEngine.invokeFunction("foo", 2, 2);
151-
});
144+
assertThrows(NoSuchMethodException.class, () -> iEngine.invokeFunction("foo", 2, 2));
152145
}
153146

154147
@Test

rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/ScriptEngineTest.java

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.mozilla.javascript.tests.scriptengine;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
44

55
import java.io.File;
66
import java.io.FileReader;
@@ -15,9 +15,9 @@
1515
import javax.script.ScriptException;
1616
import javax.script.SimpleBindings;
1717
import javax.script.SimpleScriptContext;
18-
import org.junit.Before;
19-
import org.junit.BeforeClass;
20-
import org.junit.Test;
18+
import org.junit.jupiter.api.BeforeAll;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121
import org.mozilla.javascript.engine.RhinoScriptEngine;
2222
import org.mozilla.javascript.engine.RhinoScriptEngineFactory;
2323

@@ -27,13 +27,13 @@ public class ScriptEngineTest {
2727
private ScriptEngine engine;
2828
private Compilable cEngine;
2929

30-
@BeforeClass
30+
@BeforeAll
3131
public static void initManager() {
3232
manager = new ScriptEngineManager();
3333
manager.registerEngineName("rhino", new RhinoScriptEngineFactory());
3434
}
3535

36-
@Before
36+
@BeforeEach
3737
public void init() {
3838
engine = manager.getEngineByName("rhino");
3939
cEngine = (Compilable) engine;
@@ -69,11 +69,7 @@ public void genericStatements() throws ScriptException {
6969

7070
@Test
7171
public void testThrows() {
72-
assertThrows(
73-
ScriptException.class,
74-
() -> {
75-
engine.eval("throw 'This is an error'");
76-
});
72+
assertThrows(ScriptException.class, () -> engine.eval("throw 'This is an error'"));
7773
}
7874

7975
@Test
@@ -106,11 +102,7 @@ public void engineBindings() throws IOException, ScriptException {
106102
// Make sure we can delete
107103
engineBindings.remove("string");
108104
// This will throw because string is undefined
109-
assertThrows(
110-
ScriptException.class,
111-
() -> {
112-
engine.eval("let failing = string + '123';");
113-
});
105+
assertThrows(ScriptException.class, () -> engine.eval("let failing = string + '123';"));
114106
}
115107

116108
@Test
@@ -221,10 +213,7 @@ public void compiledThrows() throws ScriptException {
221213
@Test
222214
public void cantCompile() {
223215
assertThrows(
224-
ScriptException.class,
225-
() -> {
226-
cEngine.compile("This is not JavaScript at all!");
227-
});
216+
ScriptException.class, () -> cEngine.compile("This is not JavaScript at all!"));
228217
}
229218

230219
@Test
@@ -236,20 +225,12 @@ public void languageVersion() throws ScriptException {
236225
// Older language versions
237226
ScriptEngine oldEngine = manager.getEngineByName("rhino");
238227
oldEngine.put(ScriptEngine.LANGUAGE_VERSION, 150);
239-
assertThrows(
240-
ScriptException.class,
241-
() -> {
242-
oldEngine.eval("Symbol() == Symbol()");
243-
});
228+
assertThrows(ScriptException.class, () -> oldEngine.eval("Symbol() == Symbol()"));
244229

245230
// The same with a string
246231
ScriptEngine olderEngine = manager.getEngineByName("rhino");
247232
olderEngine.put(ScriptEngine.LANGUAGE_VERSION, "150");
248-
assertThrows(
249-
ScriptException.class,
250-
() -> {
251-
olderEngine.eval("Symbol() == Symbol()");
252-
});
233+
assertThrows(ScriptException.class, () -> olderEngine.eval("Symbol() == Symbol()"));
253234
}
254235

255236
@Test

rhino-kotlin/src/test/java/org/mozilla/kotlin/tests/KotlinNullabilityDetectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import java.util.Arrays;
99
import java.util.List;
1010
import java.util.stream.Collectors;
11-
import org.junit.Test;
1211
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
1313
import org.mozilla.javascript.NullabilityDetector;
1414
import org.mozilla.kotlin.KotlinNullabilityDetector;
1515

rhino-xml/src/test/java/org/mozilla/javascript/tests/XMLSecureParserTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
package org.mozilla.javascript.tests;
66

7-
import static org.junit.Assert.assertEquals;
8-
import static org.junit.Assert.assertFalse;
9-
import static org.junit.Assert.assertTrue;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertFalse;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
1010

1111
import javax.xml.parsers.ParserConfigurationException;
12-
import org.junit.Test;
12+
import org.junit.jupiter.api.Test;
1313
import org.mozilla.javascript.Context;
1414
import org.mozilla.javascript.ContextFactory;
1515
import org.mozilla.javascript.TopLevel;

rhino-xml/src/test/java/org/mozilla/javascript/xmlimpl/tests/XmlNonResettableDocumentBuilderTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.mozilla.javascript.xmlimpl.tests;
22

3-
import org.junit.After;
4-
import org.junit.Assert;
5-
import org.junit.Before;
6-
import org.junit.Test;
3+
import org.junit.jupiter.api.AfterEach;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
77
import org.mozilla.javascript.Context;
88
import org.mozilla.javascript.ContextFactory;
99
import org.mozilla.javascript.TopLevel;
@@ -12,12 +12,12 @@ public class XmlNonResettableDocumentBuilderTest {
1212
private static final String XML_PROPERTY = "javax.xml.parsers.DocumentBuilderFactory";
1313
private final String originalDocumentBuilderFactory = System.getProperty(XML_PROPERTY);
1414

15-
@Before
15+
@BeforeEach
1616
public void setUp() {
1717
System.setProperty(XML_PROPERTY, NonResettableDocumentBuilderFactory.class.getName());
1818
}
1919

20-
@After
20+
@AfterEach
2121
public void tearDown() {
2222
if (originalDocumentBuilderFactory == null) {
2323
System.clearProperty(XML_PROPERTY);
@@ -38,7 +38,7 @@ public void nonResettableDocumentBuilder() {
3838
"source",
3939
1,
4040
null);
41-
Assert.assertEquals("John", String.valueOf(result));
41+
Assertions.assertEquals("John", String.valueOf(result));
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)