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 @@ -37,6 +37,12 @@ private CamelCaseUtil() {
}

public static String convert2CamelCase(String underScore) {
// null 또는 빈 문자열은 변환할 대상이 없으므로 그대로 반환한다.
// (빈 문자열일 때 isSkipCase의 charAt(0)에서 StringIndexOutOfBoundsException이,
// null일 때 NullPointerException이 발생하던 문제를 방지한다.)
if (underScore == null || underScore.isEmpty()) {
return underScore;
}
if (isSkipCase(underScore)) {
return underScore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* CamelCase 유틸리티 테스트 (JUnit 5)
Expand All @@ -29,4 +30,14 @@ public void convert2CamelCase() {
assertEquals("Column1Test", CamelCaseUtil.convert2CamelCase("_column_1_test_"));
}

/**
* 빈 문자열은 charAt(0)에서, null은 NullPointerException이 발생하던 것을
* 그대로 반환하도록 가드를 추가했다.
*/
@Test
public void convert2CamelCaseEmptyAndNull() {
assertEquals("", CamelCaseUtil.convert2CamelCase(""));
assertNull(CamelCaseUtil.convert2CamelCase(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ private CamelUtil() {
* @return Camel 표기법 변수명
*/
public static String convert2CamelCase(String underScore) {
// null 또는 빈 문자열은 변환할 대상이 없으므로 그대로 반환한다.
// (빈 문자열일 때 charAt(0)에서 StringIndexOutOfBoundsException이,
// null일 때 indexOf 호출에서 NullPointerException이 발생하던 문제를 방지한다.)
if (underScore == null || underScore.isEmpty()) {
return underScore;
}
// '_' 가 나타나지 않으면 이미 camel case 로 가정함.
// 단 첫째문자가 대문자이면 camel case 변환 (전체를 소문자로) 처리가
// 필요하다고 가정함. --> 아래 로직을 수행하면 바뀜
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class CamelUtilTest {

Expand All @@ -18,4 +19,14 @@ public void testConvert2CamelCase() {
assertEquals("uppercase", CamelUtil.convert2CamelCase(upperCaseString));
}

/**
* 빈 문자열은 charAt(0)에서, null은 indexOf 호출에서 예외가 발생하던 것을
* 그대로 반환하도록 가드를 추가했다.
*/
@Test
public void testConvert2CamelCaseEmptyAndNull() {
assertEquals("", CamelUtil.convert2CamelCase(""));
assertNull(CamelUtil.convert2CamelCase(null));
}

}