Skip to content

Commit d5db99d

Browse files
authored
Merge pull request #1740 from junit-team/marc/1739-fix-compile-error-on-jdk-18
Fix compile error on JDK 18 and later
2 parents 80838a5 + d1f95df commit d5db99d

File tree

8 files changed

+38
-83
lines changed

8 files changed

+38
-83
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
java: ['6', '8', '11', '17']
19+
java: ['6', '8', '11', '17', '18']
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Download Maven # Download with default JDK because OpenJDK 6 does not support TLS 1.2

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@
262262
<artifactId>maven-surefire-plugin</artifactId>
263263
<version>${surefireVersion}</version>
264264
<configuration>
265-
<test>org/junit/tests/AllTests.java</test>
265+
<includes>
266+
<include>org/junit/tests/AllTests.java</include>
267+
</includes>
266268
<useSystemClassLoader>true</useSystemClassLoader>
267269
<enableAssertions>false</enableAssertions>
268270
</configuration>

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
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public SerializedForm(Result result) {
188188
}
189189

190190
@SuppressWarnings("unchecked")
191-
private SerializedForm(ObjectInputStream.GetField fields) throws IOException {
191+
private SerializedForm(ObjectInputStream.GetField fields) throws IOException, ClassNotFoundException {
192192
fCount = (AtomicInteger) fields.get("fCount", null);
193193
fIgnoreCount = (AtomicInteger) fields.get("fIgnoreCount", null);
194194
assumptionFailureCount = (AtomicInteger) fields.get("assumptionFailureCount", null);
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)