-
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
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
test/src/test/java/io/jeyong/test/unit/SignalHandlerRegistrarTest.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,33 @@ | ||
package io.jeyong.test.unit; | ||
|
||
import static io.jeyong.handler.SignalHandlerRegistrar.SIGNAL_TYPE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.jeyong.handler.ApplicationTerminator; | ||
import io.jeyong.handler.SignalHandlerRegistrar; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import sun.misc.Signal; | ||
import sun.misc.SignalHandler; | ||
|
||
@DisplayName("SignalHandlerRegistrar Unit Test") | ||
public class SignalHandlerRegistrarTest { | ||
|
||
@Test | ||
@DisplayName("SignalHandler should be registered correctly") | ||
void testSignalHandlerRegistration() { | ||
// given | ||
SignalHandler mockSignalHandler = signal -> System.out.println("Mock signal handler"); | ||
ApplicationTerminator applicationTerminator = status -> mockSignalHandler; | ||
SignalHandlerRegistrar registrar = new SignalHandlerRegistrar(applicationTerminator); | ||
|
||
// when | ||
registrar.registerHandler(); | ||
|
||
Signal registeredSignal = new Signal(SIGNAL_TYPE); | ||
SignalHandler registeredHandler = Signal.handle(registeredSignal, null); | ||
|
||
// then | ||
assertThat(registeredHandler).isEqualTo(mockSignalHandler); | ||
} | ||
} |