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")); + } + +}