Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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 단위 테스트
*
* <p>각 생성자의 getMessage() 반환값(동작 보존)과 Throwable 표준 메시지 전파(개선)를 검증한다.</p>
*/
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());
}

}
Original file line number Diff line number Diff line change
@@ -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 단위 테스트
*
* <p>각 생성자의 getMessage() 반환값(동작 보존)과 Throwable 표준 메시지 전파(개선)를 검증한다.</p>
*/
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());
}

}