Skip to content

Commit

Permalink
Remove usage of deprecated-for-removal SecurityManager
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed May 15, 2022
1 parent 7d2a5df commit 6ba9c4d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 80 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/junit/runner/JUnitCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public class JUnitCore {
* @param args names of classes in which to find tests to run
*/
public static void main(String... args) {
System.exit(runMain(args));
}

static int runMain(String[] args) {
Result result = new JUnitCore().runMain(new RealSystem(), args);
System.exit(result.wasSuccessful() ? 0 : 1);
return result.wasSuccessful() ? 0 : 1;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/junit/runner/MainRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.junit.runner;

import java.io.OutputStream;
import java.io.PrintStream;

public class MainRunner {

public static int runMain(String... args) {
PrintStream oldOut = System.out;
System.setOut(new PrintStream(new NullOutputStream()));
try {
return JUnitCore.runMain(args);
} finally {
System.setOut(oldOut);
}
}

static class NullOutputStream extends OutputStream {
public void write(int b) {
// do nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.MainRunner;

public class CommandLineTest {
private ByteArrayOutputStream results;
Expand Down Expand Up @@ -38,11 +39,7 @@ public void test() {
@Test
public void runATest() {
testWasRun = false;
new MainRunner().runWithCheckForSystemExit(new Runnable() {
public void run() {
JUnitCore.main("org.junit.tests.running.core.CommandLineTest$Example");
}
});
MainRunner.runMain(Example.class.getName());
assertTrue(testWasRun);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.junit.Assert.fail;

import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.MainRunner;

public class JUnitCoreReturnsCorrectExitCodeTest {

Expand Down Expand Up @@ -37,11 +37,7 @@ public void successCausesExitCodeOf0() throws Exception {
}

private void runClass(final String className, int returnCode) {
Integer exitValue = new MainRunner().runWithCheckForSystemExit(new Runnable() {
public void run() {
JUnitCore.main(className);
}
});
assertEquals(Integer.valueOf(returnCode), exitValue);
int exitValue = MainRunner.runMain(className);
assertEquals(returnCode, exitValue);
}
}
67 changes: 0 additions & 67 deletions src/test/java/org/junit/tests/running/core/MainRunner.java

This file was deleted.

0 comments on commit 6ba9c4d

Please sign in to comment.