File tree Expand file tree Collapse file tree 5 files changed +33
-80
lines changed
main/java/org/junit/runner Expand file tree Collapse file tree 5 files changed +33
-80
lines changed Original file line number Diff line number Diff line change @@ -33,8 +33,12 @@ public class JUnitCore {
33
33
* @param args names of classes in which to find tests to run
34
34
*/
35
35
public static void main (String ... args ) {
36
+ System .exit (runMain (args ));
37
+ }
38
+
39
+ static int runMain (String [] args ) {
36
40
Result result = new JUnitCore ().runMain (new RealSystem (), args );
37
- System . exit ( result .wasSuccessful () ? 0 : 1 ) ;
41
+ return result .wasSuccessful () ? 0 : 1 ;
38
42
}
39
43
40
44
/**
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 10
10
import org .junit .Before ;
11
11
import org .junit .Test ;
12
12
import org .junit .runner .JUnitCore ;
13
+ import org .junit .runner .MainRunner ;
13
14
14
15
public class CommandLineTest {
15
16
private ByteArrayOutputStream results ;
@@ -38,11 +39,7 @@ public void test() {
38
39
@ Test
39
40
public void runATest () {
40
41
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 ());
46
43
assertTrue (testWasRun );
47
44
}
48
45
Original file line number Diff line number Diff line change 4
4
import static org .junit .Assert .fail ;
5
5
6
6
import org .junit .Test ;
7
- import org .junit .runner .JUnitCore ;
7
+ import org .junit .runner .MainRunner ;
8
8
9
9
public class JUnitCoreReturnsCorrectExitCodeTest {
10
10
@@ -37,11 +37,7 @@ public void successCausesExitCodeOf0() throws Exception {
37
37
}
38
38
39
39
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 );
46
42
}
47
43
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments