diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ef2a8..818f33f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log for `junit5-system-exit` ### 2.0.1 -- TBD +- Bugfix: [[#20]](https://github.com/tginsberg/junit5-system-exit/issues/20): Multiple calls to `System.exit()` do not always report the first exit status code. ### 2.0.0 - Remove terminally deprecated `SecurityManager` approach for preventing `System.exit()` calls. diff --git a/src/main/java/com/ginsberg/junit/exit/agent/AgentSystemExitHandlerStrategy.java b/src/main/java/com/ginsberg/junit/exit/agent/AgentSystemExitHandlerStrategy.java index 8996c95..95f76a2 100644 --- a/src/main/java/com/ginsberg/junit/exit/agent/AgentSystemExitHandlerStrategy.java +++ b/src/main/java/com/ginsberg/junit/exit/agent/AgentSystemExitHandlerStrategy.java @@ -39,7 +39,7 @@ public static void handleExit(final int status) { if (firstExitStatusCode == null) { firstExitStatusCode = status; } - throw new SystemExitPreventedException(status); + throw new SystemExitPreventedException(firstExitStatusCode); } else { System.exit(status); } diff --git a/src/test/java/com/ginsberg/junit/exit/assertions/SystemExitAssertionTest.java b/src/test/java/com/ginsberg/junit/exit/assertions/SystemExitAssertionTest.java index 0f48b0d..a2cd698 100644 --- a/src/test/java/com/ginsberg/junit/exit/assertions/SystemExitAssertionTest.java +++ b/src/test/java/com/ginsberg/junit/exit/assertions/SystemExitAssertionTest.java @@ -102,6 +102,18 @@ void failsWhenNoExit() { } } + @Test + void multipleCallsToExit() { + assertThatCallsSystemExit(() -> { + try { + System.exit(42); + System.exit(1); + } catch (final Exception e) { + System.exit(2); + } + }).withExitCode(42); + } + private void justExit() { System.exit(42); }