diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovException.java b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovException.java index 90d22b06..038eb65c 100755 --- a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovException.java +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovException.java @@ -33,9 +33,9 @@ */ public class EgovException extends RuntimeException { - protected EgovErrorCode egovErrorCode; + private static final long serialVersionUID = 1L; - protected String message; + protected EgovErrorCode egovErrorCode; public EgovException(EgovErrorCode egovErrorCode) { this(egovErrorCode, true, null); @@ -50,17 +50,12 @@ public EgovException(EgovErrorCode egovErrorCode, String message) { } public EgovException(EgovErrorCode egovErrorCode, boolean messageCode, String message) { + super(messageCode ? egovErrorCode.getMessage() : message); this.egovErrorCode = egovErrorCode; - if (messageCode) message = egovErrorCode.getMessage(); - this.message = message; } public EgovErrorCode getEgovErrorCode() { return egovErrorCode; } - public String getMessage() { - return message; - } - } diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceException.java b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceException.java index 8b67614c..10f3fe94 100755 --- a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceException.java +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceException.java @@ -33,25 +33,21 @@ */ public class EgovServiceException extends RuntimeException { - protected EgovErrorCode egovErrorCode; + private static final long serialVersionUID = 1L; - protected String message; + protected EgovErrorCode egovErrorCode; public EgovServiceException(String message) { this(EgovErrorCode.INTERNAL_SERVER_ERROR, message); } public EgovServiceException(EgovErrorCode egovErrorCode, String message) { + super(message); this.egovErrorCode = egovErrorCode; - this.message = message; } public EgovErrorCode getEgovErrorCode() { return egovErrorCode; } - public String getMessage() { - return message; - } - } diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionTest.java b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionTest.java new file mode 100644 index 00000000..c87885ad --- /dev/null +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2008-2024 MOIS(Ministry of the Interior and Safety). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.egovframe.rte.ptl.reactive.exception; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +/** + * EgovException 단위 테스트 + * + *
각 생성자의 getMessage() 반환값(동작 보존)과 Throwable 표준 메시지 전파(개선)를 검증한다.
+ */ +public class EgovExceptionTest { + + @Test + public void messageConstructor() { + EgovException ex = new EgovException("invalid"); + + assertEquals("invalid", ex.getMessage()); + assertSame(EgovErrorCode.INVALID_INPUT_VALUE, ex.getEgovErrorCode()); + } + + @Test + public void errorCodeAndMessageConstructor() { + EgovException ex = new EgovException(EgovErrorCode.NOT_FOUND, "custom"); + + assertEquals("custom", ex.getMessage()); + assertSame(EgovErrorCode.NOT_FOUND, ex.getEgovErrorCode()); + } + + @Test + public void errorCodeConstructorUsesErrorCodeMessage() { + EgovException ex = new EgovException(EgovErrorCode.NOT_FOUND); + + assertEquals(EgovErrorCode.NOT_FOUND.getMessage(), ex.getMessage()); + assertSame(EgovErrorCode.NOT_FOUND, ex.getEgovErrorCode()); + } + + @Test + public void messageIsPropagatedToThrowable() { + RuntimeException re = new EgovException(EgovErrorCode.NOT_FOUND, "custom"); + + // 수정 전에는 super(message)를 호출하지 않아 null 이었음(개선 입증) + assertEquals("custom", re.getMessage()); + } + +} diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceExceptionTest.java b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceExceptionTest.java new file mode 100644 index 00000000..a68ae81c --- /dev/null +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovServiceExceptionTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2008-2024 MOIS(Ministry of the Interior and Safety). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.egovframe.rte.ptl.reactive.exception; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +/** + * EgovServiceException 단위 테스트 + * + *각 생성자의 getMessage() 반환값(동작 보존)과 Throwable 표준 메시지 전파(개선)를 검증한다.
+ */ +public class EgovServiceExceptionTest { + + @Test + public void messageConstructor() { + EgovServiceException ex = new EgovServiceException("failed"); + + assertEquals("failed", ex.getMessage()); + assertSame(EgovErrorCode.INTERNAL_SERVER_ERROR, ex.getEgovErrorCode()); + } + + @Test + public void errorCodeAndMessageConstructor() { + EgovServiceException ex = new EgovServiceException(EgovErrorCode.SERVICE_UNAVAILABLE, "failed"); + + assertEquals("failed", ex.getMessage()); + assertSame(EgovErrorCode.SERVICE_UNAVAILABLE, ex.getEgovErrorCode()); + } + + @Test + public void messageIsPropagatedToThrowable() { + RuntimeException re = new EgovServiceException(EgovErrorCode.SERVICE_UNAVAILABLE, "failed"); + + // 수정 전에는 super(message)를 호출하지 않아 null 이었음(개선 입증) + assertEquals("failed", re.getMessage()); + } + +}