diff --git a/test/build.gradle b/test/build.gradle index 5cdfeb8..d59b9a2 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -28,6 +28,7 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'org.testcontainers:junit-jupiter:1.20.4' testImplementation 'org.testcontainers:testcontainers:1.20.4' + testImplementation 'com.github.stefanbirkner:system-lambda:1.2.1' } tasks.named('test') { diff --git a/test/src/test/java/io/jeyong/test/unit/SignalHandlerRegistrarTest.java b/test/src/test/java/io/jeyong/test/unit/SignalHandlerRegistrarTest.java new file mode 100644 index 0000000..52f4e6c --- /dev/null +++ b/test/src/test/java/io/jeyong/test/unit/SignalHandlerRegistrarTest.java @@ -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); + } +}