Skip to content

Commit

Permalink
test: 종료 신호를 처리하는 객체를 등록하는 것을 검증
Browse files Browse the repository at this point in the history
  • Loading branch information
joon6093 committed Nov 23, 2024
1 parent cc233cf commit ad6ec1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
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);
}
}

0 comments on commit ad6ec1a

Please sign in to comment.