Skip to content

Commit

Permalink
✅ test : add errorcode duplication test
Browse files Browse the repository at this point in the history
  • Loading branch information
seonghun-dev committed Jan 27, 2024
1 parent a0c4d0c commit 3e718d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum CommonErrorCode implements ErrorCodeInterface {
* Basic Server Error
*/
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON_INTERNAL_SERVER_ERROR", "Internal Server Error", "An unexpected error occurred"),
NOT_IMPLEMENTED(HttpStatus.NOT_IMPLEMENTED, "COMMON_INTERNAL_SERVER_ERROR", "Not Implemented", "The server does not support the functionality required to fulfill the request.");
NOT_IMPLEMENTED(HttpStatus.NOT_IMPLEMENTED, "COMMON_NOT_IMPLEMENTED", "Not Implemented", "The server does not support the functionality required to fulfill the request.");


private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public enum UserErrorCode implements ErrorCodeInterface {
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER_NOT_FOUND", "User Not Found", "User with the corresponding id could not be found"),
INVALID_USER_EXCEPTION(HttpStatus.FORBIDDEN, "USER_FORBIDDEN", "User does not have permission", "Modify or Delete Not Permitted"),
INVALID_INPUT_EXCEPTION(HttpStatus.BAD_REQUEST, "USER_NOT_FOUND", "C-0015", "Nickname must be at least 1 character and not more than 10 characters"),
USER_NICKNAME_INVALID(HttpStatus.BAD_REQUEST, "USER_NICKNAME_INVALID", "User nickname is invalid", "Nickname must be at least 1 character and not more than 10 characters"),
USER_CAN_NOT_BLOCK_SELF(HttpStatus.BAD_REQUEST, "USER_CAN_NOT_BLOCK_SELF", "Can Not Block Myself", "You can't block yourself");

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package unit.common.error;

import com.depromeet.common.error.dto.StreetDropErrorCode;
import com.depromeet.common.error.dto.StreetDropErrorCodeList;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertTrue;


@DisplayName("에러 코드 테스트")
public class StreetDropErrorCodeTest {
@Test
@DisplayName("다른 도메인의 에러 코드가 중복되지 않는지 테스트")
public void testNoDuplicateErrorResponseCodes() {

StreetDropErrorCodeList streetDropErrorCodeList = StreetDropErrorCodeList.getInstance();
List<StreetDropErrorCode> errorCodes = streetDropErrorCodeList.getStreetDropErrorCodeList();

List<String> errorResponseCodes = errorCodes.stream()
.map(StreetDropErrorCode::getErrorResponseCode)
.toList();

var duplicatedList = errorResponseCodes.stream()
.filter(i -> errorResponseCodes.stream().filter(i::equals).count() > 1)
.distinct()
.toList();

assertTrue(duplicatedList.isEmpty(), "There are duplicated error response codes: " + duplicatedList);
}

}

0 comments on commit 3e718d2

Please sign in to comment.