-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
test/src/test/java/io/jeyong/test/unit/SystemTerminatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.jeyong.test.unit; | ||
|
||
import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit; | ||
import static io.jeyong.handler.SignalHandlerRegistrar.EXIT_CODE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.jeyong.handler.SystemTerminator; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import sun.misc.SignalHandler; | ||
|
||
@DisplayName("SystemTerminator Unit Test") | ||
public class SystemTerminatorTest { | ||
|
||
@Test | ||
@DisplayName("System.exit should be called with the expected status code") | ||
void testHandleTerminationCallsSystemExit() throws Exception { | ||
// given | ||
SystemTerminator terminator = new SystemTerminator(); | ||
int expectedStatusCode = EXIT_CODE; | ||
SignalHandler handler = terminator.handleTermination(expectedStatusCode); | ||
|
||
// when | ||
int actualExitCode = catchSystemExit(() -> handler.handle(null)); | ||
|
||
// then | ||
assertThat(actualExitCode).isEqualTo(expectedStatusCode); | ||
} | ||
} |