From ad6ec1a8ad274b9901a6f130390bfb328a3b0f48 Mon Sep 17 00:00:00 2001 From: jeyong Date: Sun, 24 Nov 2024 04:55:19 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=A2=85=EB=A3=8C=20=EC=8B=A0=ED=98=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=8A=94=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EB=A5=BC=20=EB=93=B1=EB=A1=9D=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B2=83=EC=9D=84=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/build.gradle | 1 + .../test/unit/SignalHandlerRegistrarTest.java | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/src/test/java/io/jeyong/test/unit/SignalHandlerRegistrarTest.java 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); + } +}