Skip to content

Commit b23126b

Browse files
authored
Release v2.0.2 (#26)
* Prepare v2.0.2 * Fix #24 - Reset state between assertion calls (#25) + Add test dependency: Assertj * Release v2.0.2
1 parent 3981ad6 commit b23126b

6 files changed

Lines changed: 28 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log for `junit5-system-exit`
22

3+
### 2.0.2
4+
- Bugfix: [[#24]](https://github.com/tginsberg/junit5-system-exit/issues/24): Reset state between assertion calls.
5+
36
### 2.0.1
47
- 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.
58

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ your test task. Please consult the [FAQ](#faq) below if you run into problems.
2828
#### 1. Copy the following into your `build.gradle` or `build.gradle.kts`.
2929

3030
```groovy
31-
testImplementation("com.ginsberg:junit5-system-exit:2.0.1")
31+
testImplementation("com.ginsberg:junit5-system-exit:2.0.2")
3232
```
3333

3434
#### 2. Enable the Java Agent
@@ -73,7 +73,7 @@ test {
7373
<dependency>
7474
<groupId>com.ginsberg</groupId>
7575
<artifactId>junit5-system-exit</artifactId>
76-
<version>2.0.1</version>
76+
<version>2.0.2</version>
7777
<scope>test</scope>
7878
</dependency>
7979
```

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dependencies {
7171
because("Starting in Gradle 9.0, this needs to be an explicitly declared dependency")
7272
}
7373

74+
testImplementation("org.assertj:assertj-core:3.26.3")
7475
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
7576
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
7677
testImplementation("org.junit.platform:junit-platform-launcher:$junitPlatformLauncherVersion")

src/main/java/com/ginsberg/junit/exit/assertions/SystemExitAssertion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private SystemExitAssertion didNotCallSystemExit() {
6565
private static SystemExitPreventedException catchSystemExitFrom(final Runnable function) {
6666
final ExitPreventerStrategy exitPreventerStrategy = new AgentSystemExitHandlerStrategy();
6767
try {
68+
exitPreventerStrategy.resetBetweenTests();
6869
exitPreventerStrategy.beforeTest();
6970
function.run();
7071
} catch (SystemExitPreventedException e) {

src/test/java/com/ginsberg/junit/exit/assertions/SystemExitAssertionTest.java

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,63 @@
55

66
import static com.ginsberg.junit.exit.assertions.SystemExitAssertion.assertThatCallsSystemExit;
77
import static com.ginsberg.junit.exit.assertions.SystemExitAssertion.assertThatDoesNotCallSystemExit;
8+
import static org.assertj.core.api.Assertions.assertThat;
89
import static org.junit.jupiter.api.Assertions.assertEquals;
910
import static org.junit.jupiter.api.Assertions.fail;
1011

1112
class SystemExitAssertionTest {
1213

1314
@Test
1415
void catchesExit() {
15-
assertThatCallsSystemExit(() -> System.exit(42));
16+
assertThatCallsSystemExit(() -> System.exit(1));
1617
}
1718

1819
@Test
1920
void catchesExitWithCode() {
20-
assertThatCallsSystemExit(() -> System.exit(42)).withExitCode(42);
21+
assertThatCallsSystemExit(() -> System.exit(2)).withExitCode(2);
2122
}
2223

2324
@Test
2425
void catchesExitWithCodeInRange() {
25-
assertThatCallsSystemExit(() -> System.exit(42)).withExitCodeInRange(41, 43);
26+
assertThatCallsSystemExit(() -> System.exit(3)).withExitCodeInRange(1, 3);
2627
}
2728

2829
@Test
2930
void catchesMultipleExits() {
3031
assertThatCallsSystemExit(() -> {
31-
justExit();
32-
justExit();
33-
justExit();
34-
}).withExitCode(42);
32+
System.exit(4);
33+
System.exit(5);
34+
System.exit(6);
35+
}).withExitCode(4);
3536
}
3637

3738
@Test
3839
void exitCodeDoesNotMatch() {
3940
try {
40-
assertThatCallsSystemExit(() -> System.exit(42)).withExitCode(43);
41+
assertThatCallsSystemExit(() -> System.exit(5)).withExitCode(6);
4142
fail("Should have failed test when System.exit was not called but expected");
4243
} catch (AssertionFailedError e) {
43-
// Expected
44+
assertThat(e.getMessage()).startsWith("Wrong exit code found");
4445
}
4546
}
4647

4748
@Test
4849
void exitCodeNotInRangeHigh() {
4950
try {
50-
assertThatCallsSystemExit(() -> System.exit(44)).withExitCodeInRange(41, 43);
51+
assertThatCallsSystemExit(() -> System.exit(7)).withExitCodeInRange(1, 6);
5152
fail("Should have failed test when System.exit was not in range");
5253
} catch (AssertionFailedError e) {
53-
// Expected
54+
assertThat(e.getMessage()).startsWith("Exit code expected in range (1 .. 6) but was 7");
5455
}
5556
}
5657

5758
@Test
5859
void exitCodeNotInRangeLow() {
5960
try {
60-
assertThatCallsSystemExit(() -> System.exit(40)).withExitCodeInRange(41,43);
61+
assertThatCallsSystemExit(() -> System.exit(8)).withExitCodeInRange(9, 11);
6162
fail("Should have failed test when System.exit was not in range");
6263
} catch (AssertionFailedError e) {
63-
// Expected
64+
assertThat(e.getMessage()).startsWith("Exit code expected in range (9 .. 11) but was 8");
6465
}
6566
}
6667

@@ -73,11 +74,11 @@ void expectingNoExit() {
7374
void expectingNoExitWhenExitHappens() {
7475
try {
7576
assertThatDoesNotCallSystemExit(() ->
76-
System.exit(42)
77+
System.exit(9)
7778
);
7879
fail("Should have failed test when System.exit was called but not expected");
7980
} catch (AssertionFailedError e) {
80-
// Expected
81+
assertThat(e.getMessage()).startsWith("Unexpected call to System.exit()");
8182
}
8283
}
8384

@@ -86,35 +87,19 @@ void expectingSystemExitButSomethingElseThrown() {
8687
try {
8788
assertThatCallsSystemExit(() -> {
8889
throw new IllegalStateException();
89-
}).withExitCode(42);
90-
} catch(final Exception e) {
90+
}).withExitCode(10);
91+
} catch (final Exception e) {
9192
assertEquals(IllegalStateException.class, e.getCause().getClass());
9293
}
9394
}
9495

9596
@Test
9697
void failsWhenNoExit() {
9798
try {
98-
assertThatCallsSystemExit(System::currentTimeMillis).withExitCode(42);
99+
assertThatCallsSystemExit(System::currentTimeMillis).withExitCode(11);
99100
fail("Should have failed test when System.exit was not called but expected");
100101
} catch (AssertionFailedError e) {
101-
// Expected
102+
assertThat(e.getMessage()).startsWith("Expected call to System.exit() did not happen");
102103
}
103104
}
104-
105-
@Test
106-
void multipleCallsToExit() {
107-
assertThatCallsSystemExit(() -> {
108-
try {
109-
System.exit(42);
110-
System.exit(1);
111-
} catch (final Exception e) {
112-
System.exit(2);
113-
}
114-
}).withExitCode(42);
115-
}
116-
117-
private void justExit() {
118-
System.exit(42);
119-
}
120105
}

0 commit comments

Comments
 (0)