Skip to content
Merged
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 @@ -46,10 +46,10 @@ void setUp() {
}

@Test
@DisplayName("제목이 15자를 초과하면 검증에 실패한다")
@DisplayName("제목이 40자를 초과하면 검증에 실패한다")
void title_Size_초과_실패() {
// given
String longTitle = "a".repeat(16);
String longTitle = "a".repeat(41);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

41과 같은 매직 넘버는 코드의 가독성과 유지보수성을 저해할 수 있습니다. 클래스 수준에 private static final int TITLE_MAX_LENGTH = 40;와 같은 상수를 선언하고, 여기서는 TITLE_MAX_LENGTH + 1을 사용하는 것이 좋습니다. 이렇게 하면 제목 최대 길이가 변경될 때 상수의 값만 수정하면 되므로 유지보수가 용이해집니다. 이 파일의 PostUpdateDtoValidationTest 내의 유사한 테스트(163행)에도 동일하게 적용하는 것을 고려해주세요.


PostCreateDto.CreateFree dto = new PostCreateDto.CreateFree(
longTitle,
Expand All @@ -65,7 +65,7 @@ void setUp() {

// then
assertThat(violations).hasSize(1);
assertThat(violations.iterator().next().getMessage()).isEqualTo("제목은 15자를 초과할 수 없습니다");
assertThat(violations.iterator().next().getMessage()).isEqualTo("제목은 40자를 초과할 수 없습니다");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

에러 메시지 문자열에 하드코딩된 40이 있습니다. 앞서 제안한 TITLE_MAX_LENGTH 상수를 사용하면, "제목은 " + TITLE_MAX_LENGTH + "자를 초과할 수 없습니다"와 같이 에러 메시지를 동적으로 생성하여 일관성을 유지하고 향후 변경에 더 쉽게 대응할 수 있습니다. 이 파일의 PostUpdateDtoValidationTest 내의 유사한 테스트(179행)에도 동일하게 적용할 수 있습니다.

}

@Test
Expand Down Expand Up @@ -157,10 +157,10 @@ void setUp() {
class PostUpdateDtoValidationTest {

@Test
@DisplayName("제목이 15자를 초과하면 검증에 실패한다")
@DisplayName("제목이 40자를 초과하면 검증에 실패한다")
void title_Size_초과_실패() {
// given
String longTitle = "a".repeat(16);
String longTitle = "a".repeat(41);

PostUpdateDto.UpdateFree dto = new PostUpdateDto.UpdateFree(
longTitle,
Expand All @@ -176,7 +176,7 @@ class PostUpdateDtoValidationTest {

// then
assertThat(violations).hasSize(1);
assertThat(violations.iterator().next().getMessage()).isEqualTo("제목은 15자를 초과할 수 없습니다");
assertThat(violations.iterator().next().getMessage()).isEqualTo("제목은 40자를 초과할 수 없습니다");
}

@Test
Expand Down Expand Up @@ -242,10 +242,10 @@ class PostUpdateDtoValidationTest {
}

@Test
@DisplayName("제목이 15자 정확히 입력되면 검증에 성공한다")
void title_15자_정확히_성공() {
@DisplayName("제목이 40자 정확히 입력되면 검증에 성공한다")
void title_40자_정확히_성공() {
// given
String exactTitle = "a".repeat(15); // 정확히 15자
String exactTitle = "a".repeat(40); // 정확히 40자

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

경계값 테스트에서도 40이라는 매직 넘버 대신 TITLE_MAX_LENGTH와 같은 상수를 사용하는 것이 좋습니다. 이렇게 하면 이 숫자가 제목의 최대 길이를 의미한다는 것이 명확해지고, 코드의 가독성과 유지보수성이 향상됩니다.


PostUpdateDto.UpdateFree dto = new PostUpdateDto.UpdateFree(
exactTitle,
Expand Down
Loading