From 4fbd2870d49652d1ae5213882ce05339dbf8e556 Mon Sep 17 00:00:00 2001 From: dasomel Date: Thu, 28 May 2026 00:42:23 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=98=88=EC=99=B8=20=ED=95=B8=EB=93=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EgovSampleExcepHndlr, EgovSampleOthersExcepHndlr, EgovAopExceptionTransfer 세 클래스에 대한 JUnit 5 단위 테스트를 추가한다. - EgovSampleExcepHndlrTest: occur() 메서드가 다양한 예외 유형에서 예외를 전파하지 않고 정상 처리됨을 검증 (3건) - EgovSampleOthersExcepHndlrTest: 동일한 패턴으로 others 핸들러 검증 (3건) - EgovAopExceptionTransferTest: Mockito로 ExceptionTransfer.transfer() 위임 호출 여부 검증 (2건) --- .../EgovAopExceptionTransferTest.java | 57 +++++++++++++++++++ .../exception/EgovSampleExcepHndlrTest.java | 45 +++++++++++++++ .../EgovSampleOthersExcepHndlrTest.java | 45 +++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 src/test/java/egovframework/example/exception/EgovAopExceptionTransferTest.java create mode 100644 src/test/java/egovframework/example/exception/EgovSampleExcepHndlrTest.java create mode 100644 src/test/java/egovframework/example/exception/EgovSampleOthersExcepHndlrTest.java diff --git a/src/test/java/egovframework/example/exception/EgovAopExceptionTransferTest.java b/src/test/java/egovframework/example/exception/EgovAopExceptionTransferTest.java new file mode 100644 index 0000000..ef7d7f0 --- /dev/null +++ b/src/test/java/egovframework/example/exception/EgovAopExceptionTransferTest.java @@ -0,0 +1,57 @@ +package egovframework.example.exception; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.aspectj.lang.JoinPoint; +import org.egovframe.rte.fdl.cmmn.aspect.ExceptionTransfer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * EgovAopExceptionTransfer 단위 테스트 + * + * @author 이백행 + * @since 2025-05-28 + */ +class EgovAopExceptionTransferTest { + + private EgovAopExceptionTransfer exceptionTransfer; + private ExceptionTransfer mockExceptionTransfer; + + @BeforeEach + void setUp() { + exceptionTransfer = new EgovAopExceptionTransfer(); + mockExceptionTransfer = mock(ExceptionTransfer.class); + exceptionTransfer.setExceptionTransfer(mockExceptionTransfer); + } + + @Test + @DisplayName("doAfterThrowingExceptionTransferService - ExceptionTransfer.transfer 위임 확인") + void testDoAfterThrowingDelegatesToExceptionTransfer() throws Exception { + JoinPoint joinPoint = mock(JoinPoint.class); + Exception ex = new RuntimeException("서비스 예외"); + + exceptionTransfer.doAfterThrowingExceptionTransferService(joinPoint, ex); + + verify(mockExceptionTransfer).transfer(eq(joinPoint), eq(ex)); + } + + @Test + @DisplayName("setExceptionTransfer - 의존성 주입 후 transfer 호출 가능") + void testSetExceptionTransfer() throws Exception { + ExceptionTransfer another = mock(ExceptionTransfer.class); + exceptionTransfer.setExceptionTransfer(another); + + JoinPoint joinPoint = mock(JoinPoint.class); + Exception ex = new IllegalStateException("상태 예외"); + + exceptionTransfer.doAfterThrowingExceptionTransferService(joinPoint, ex); + + verify(another).transfer(any(JoinPoint.class), eq(ex)); + } + +} diff --git a/src/test/java/egovframework/example/exception/EgovSampleExcepHndlrTest.java b/src/test/java/egovframework/example/exception/EgovSampleExcepHndlrTest.java new file mode 100644 index 0000000..89d489b --- /dev/null +++ b/src/test/java/egovframework/example/exception/EgovSampleExcepHndlrTest.java @@ -0,0 +1,45 @@ +package egovframework.example.exception; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * EgovSampleExcepHndlr 단위 테스트 + * + * @author 이백행 + * @since 2025-05-28 + */ +class EgovSampleExcepHndlrTest { + + private EgovSampleExcepHndlr handler; + + @BeforeEach + void setUp() { + handler = new EgovSampleExcepHndlr(); + } + + @Test + @DisplayName("occur 메서드 - RuntimeException 발생 시 예외 없이 처리") + void testOccurWithRuntimeException() { + RuntimeException ex = new RuntimeException("테스트 예외"); + assertDoesNotThrow(() -> handler.occur(ex, "egovframework.example")); + } + + @Test + @DisplayName("occur 메서드 - 일반 Exception 발생 시 예외 없이 처리") + void testOccurWithException() { + Exception ex = new Exception("일반 예외"); + assertDoesNotThrow(() -> handler.occur(ex, "egovframework.example.sample")); + } + + @Test + @DisplayName("occur 메서드 - 빈 패키지명으로 호출 시 예외 없이 처리") + void testOccurWithEmptyPackageName() { + Exception ex = new IllegalArgumentException("잘못된 인수"); + assertDoesNotThrow(() -> handler.occur(ex, "")); + } + +} diff --git a/src/test/java/egovframework/example/exception/EgovSampleOthersExcepHndlrTest.java b/src/test/java/egovframework/example/exception/EgovSampleOthersExcepHndlrTest.java new file mode 100644 index 0000000..8ce3269 --- /dev/null +++ b/src/test/java/egovframework/example/exception/EgovSampleOthersExcepHndlrTest.java @@ -0,0 +1,45 @@ +package egovframework.example.exception; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * EgovSampleOthersExcepHndlr 단위 테스트 + * + * @author 이백행 + * @since 2025-05-28 + */ +class EgovSampleOthersExcepHndlrTest { + + private EgovSampleOthersExcepHndlr handler; + + @BeforeEach + void setUp() { + handler = new EgovSampleOthersExcepHndlr(); + } + + @Test + @DisplayName("occur 메서드 - RuntimeException 발생 시 예외 없이 처리") + void testOccurWithRuntimeException() { + RuntimeException ex = new RuntimeException("런타임 예외"); + assertDoesNotThrow(() -> handler.occur(ex, "egovframework.example")); + } + + @Test + @DisplayName("occur 메서드 - 일반 Exception 발생 시 예외 없이 처리") + void testOccurWithException() { + Exception ex = new Exception("일반 예외"); + assertDoesNotThrow(() -> handler.occur(ex, "egovframework.example.sample")); + } + + @Test + @DisplayName("occur 메서드 - NullPointerException 발생 시 예외 없이 처리") + void testOccurWithNullPointerException() { + NullPointerException ex = new NullPointerException("널 포인터 예외"); + assertDoesNotThrow(() -> handler.occur(ex, "egovframework.example.service")); + } + +}