Skip to content

Commit

Permalink
Merge pull request #1740 from junit-team/marc/1739-fix-compile-error-…
Browse files Browse the repository at this point in the history
…on-jdk-18

Fix compile error on JDK 18 and later
  • Loading branch information
kcooney authored Nov 17, 2022
2 parents 80838a5 + d1f95df commit d5db99d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: ['6', '8', '11', '17']
java: ['6', '8', '11', '17', '18']
steps:
- uses: actions/checkout@v2
- name: Download Maven # Download with default JDK because OpenJDK 6 does not support TLS 1.2
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefireVersion}</version>
<configuration>
<test>org/junit/tests/AllTests.java</test>
<includes>
<include>org/junit/tests/AllTests.java</include>
</includes>
<useSystemClassLoader>true</useSystemClassLoader>
<enableAssertions>false</enableAssertions>
</configuration>
Expand Down
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
2 changes: 1 addition & 1 deletion src/main/java/org/junit/runner/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public SerializedForm(Result result) {
}

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

Please sign in to comment.