Skip to content

Commit 6ba9c4d

Browse files
committed
Remove usage of deprecated-for-removal SecurityManager
1 parent 7d2a5df commit 6ba9c4d

File tree

5 files changed

+33
-80
lines changed

5 files changed

+33
-80
lines changed

src/main/java/org/junit/runner/JUnitCore.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ public class JUnitCore {
3333
* @param args names of classes in which to find tests to run
3434
*/
3535
public static void main(String... args) {
36+
System.exit(runMain(args));
37+
}
38+
39+
static int runMain(String[] args) {
3640
Result result = new JUnitCore().runMain(new RealSystem(), args);
37-
System.exit(result.wasSuccessful() ? 0 : 1);
41+
return result.wasSuccessful() ? 0 : 1;
3842
}
3943

4044
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.junit.runner;
2+
3+
import java.io.OutputStream;
4+
import java.io.PrintStream;
5+
6+
public class MainRunner {
7+
8+
public static int runMain(String... args) {
9+
PrintStream oldOut = System.out;
10+
System.setOut(new PrintStream(new NullOutputStream()));
11+
try {
12+
return JUnitCore.runMain(args);
13+
} finally {
14+
System.setOut(oldOut);
15+
}
16+
}
17+
18+
static class NullOutputStream extends OutputStream {
19+
public void write(int b) {
20+
// do nothing
21+
}
22+
}
23+
}

src/test/java/org/junit/tests/running/core/CommandLineTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.junit.Before;
1111
import org.junit.Test;
1212
import org.junit.runner.JUnitCore;
13+
import org.junit.runner.MainRunner;
1314

1415
public class CommandLineTest {
1516
private ByteArrayOutputStream results;
@@ -38,11 +39,7 @@ public void test() {
3839
@Test
3940
public void runATest() {
4041
testWasRun = false;
41-
new MainRunner().runWithCheckForSystemExit(new Runnable() {
42-
public void run() {
43-
JUnitCore.main("org.junit.tests.running.core.CommandLineTest$Example");
44-
}
45-
});
42+
MainRunner.runMain(Example.class.getName());
4643
assertTrue(testWasRun);
4744
}
4845

src/test/java/org/junit/tests/running/core/JUnitCoreReturnsCorrectExitCodeTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static org.junit.Assert.fail;
55

66
import org.junit.Test;
7-
import org.junit.runner.JUnitCore;
7+
import org.junit.runner.MainRunner;
88

99
public class JUnitCoreReturnsCorrectExitCodeTest {
1010

@@ -37,11 +37,7 @@ public void successCausesExitCodeOf0() throws Exception {
3737
}
3838

3939
private void runClass(final String className, int returnCode) {
40-
Integer exitValue = new MainRunner().runWithCheckForSystemExit(new Runnable() {
41-
public void run() {
42-
JUnitCore.main(className);
43-
}
44-
});
45-
assertEquals(Integer.valueOf(returnCode), exitValue);
40+
int exitValue = MainRunner.runMain(className);
41+
assertEquals(returnCode, exitValue);
4642
}
4743
}

src/test/java/org/junit/tests/running/core/MainRunner.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)