Skip to content
Merged
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 @@ -2,14 +2,15 @@

import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;

import com.nexters.teamace.user.domain.User;
import org.springframework.util.StringUtils;

public record LoginCommand(String username) {
public LoginCommand {
if (!StringUtils.hasText(username)) {
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
}
if (username.length() > 20) {
if (username.length() > User.MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException(USERNAME_SIZE);
Comment on lines +13 to 14
Copy link
Member

Choose a reason for hiding this comment

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

매직 넘버 제거한 거 아주 좋습니다👍👍👍👍

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;

import com.nexters.teamace.user.domain.User;
import org.springframework.util.StringUtils;

public record SignupCommand(String username, String nickname) {
public SignupCommand {
if (!StringUtils.hasText(username)) {
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
}
if (username.length() > 20) {
if (username.length() > User.MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException(USERNAME_SIZE);
}
if (!StringUtils.hasText(nickname)) {
throw new IllegalArgumentException(NICKNAME_NOT_BLANK);
}
if (nickname.length() > 20) {
if (nickname.length() > User.MAX_NICKNAME_LENGTH) {
throw new IllegalArgumentException(NICKNAME_SIZE);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.nexters.teamace.auth.presentation;

import com.nexters.teamace.common.exception.ValidationErrorMessage;
import com.nexters.teamace.user.domain.User;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record SignupRequest(
@NotBlank(message = ValidationErrorMessage.USERNAME_NOT_BLANK)
@Size(min = 1, max = 20, message = ValidationErrorMessage.USERNAME_SIZE)
@Size(
min = 1,
max = User.MAX_USERNAME_LENGTH,
message = ValidationErrorMessage.USERNAME_SIZE)
String username,
@NotBlank(message = ValidationErrorMessage.NICKNAME_NOT_BLANK)
@Size(min = 1, max = 20, message = ValidationErrorMessage.NICKNAME_SIZE)
@Size(
min = 1,
max = User.MAX_NICKNAME_LENGTH,
message = ValidationErrorMessage.NICKNAME_SIZE)
String nickname) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.teamace.common.exception;

import com.nexters.teamace.user.domain.User;

public class ValidationErrorMessage {

/** Auth */
Expand All @@ -9,9 +11,11 @@ public class ValidationErrorMessage {
public static final String USER_ID_NOT_NULL = "User ID cannot be null";

public static final String USER_ID_POSITIVE = "User ID must be greater than or equal to 1";
public static final String USERNAME_SIZE = "Username must be between 1 and 20 characters";
public static final String USERNAME_SIZE =
"Username must be between 1 and " + User.MAX_USERNAME_LENGTH + " characters";

public static final String NICKNAME_SIZE = "Nickname must be between 1 and 20 characters";
public static final String NICKNAME_SIZE =
"Nickname must be between 1 and " + User.MAX_NICKNAME_LENGTH + " characters";
public static final String USERNAME_NOT_BLANK = "username must not be blank";
public static final String NICKNAME_NOT_BLANK = "nickname must not be blank";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;

import com.nexters.teamace.user.domain.User;
import org.springframework.util.StringUtils;

public record CreateUserCommand(String username, String nickname) {
Expand All @@ -10,15 +11,15 @@ public record CreateUserCommand(String username, String nickname) {
if (!StringUtils.hasText(username)) {
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
}
if (username.length() > 20) {
if (username.length() > User.MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException(USERNAME_SIZE);
}
}
if (nickname != null) {
if (!StringUtils.hasText(nickname)) {
throw new IllegalArgumentException(NICKNAME_NOT_BLANK);
}
if (nickname.length() > 20) {
if (nickname.length() > User.MAX_NICKNAME_LENGTH) {
throw new IllegalArgumentException(NICKNAME_SIZE);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/nexters/teamace/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@NoArgsConstructor(access = PROTECTED)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class User {
public static final int MAX_USERNAME_LENGTH = 50;
public static final int MAX_NICKNAME_LENGTH = 20;

@Getter @EqualsAndHashCode.Include private Long id;
@Getter private String username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ void it_throws_IllegalArgumentException() {
}

@Nested
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
class Context_when_creating_with_username_longer_than_20_characters {

@Test
@DisplayName("IllegalArgumentException을 던진다")
void it_throws_IllegalArgumentException() {
final String longUsername = "a".repeat(21);
final String longUsername = "a".repeat(51);

thenThrownBy(() -> new LoginCommand(longUsername))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Username must be between 1 and 20 characters");
.hasMessage("Username must be between 1 and 50 characters");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ void it_throws_IllegalArgumentException() {
}

@Nested
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
class Context_when_creating_with_username_longer_than_20_characters {

@Test
@DisplayName("IllegalArgumentException을 던진다")
void it_throws_IllegalArgumentException() {
final String longUsername = "a".repeat(21);
final String longUsername = "a".repeat(51);

thenThrownBy(() -> new SignupCommand(longUsername, "Valid User"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Username must be between 1 and 20 characters");
.hasMessage("Username must be between 1 and 50 characters");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ void it_throws_IllegalArgumentException() {
}

@Nested
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
class Context_when_creating_with_username_longer_than_20_characters {

@Test
@DisplayName("IllegalArgumentException을 던진다")
void it_throws_IllegalArgumentException() {
final String longUsername = "a".repeat(21);
final String longUsername = "a".repeat(51);

thenThrownBy(() -> new CreateUserCommand(longUsername, "Valid User"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Username must be between 1 and 20 characters");
.hasMessage("Username must be between 1 and 50 characters");
Comment on lines +69 to +79
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

레거시 명칭/문구 잔존 여부 점검 스크립트

다른 테스트의 컨텍스트 클래스명이나 메시지에 ..._20_characters가 남아 있을 수 있습니다. 아래 스크립트로 점검해 보세요. Username 관련해서는 더 이상 "20"이 남지 않는 것이 기대 결과입니다.


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "컨텍스트 클래스명에 'longer_than_20_characters' 잔존 검색"
rg -nP -C2 'longer_than_20_characters' --type=java

echo
echo "Username 관련 'between 1 and 20 characters' 메시지 잔존 검색"
rg -nP -C2 'Username must be between 1 and 20 characters' --type=java

Length of output: 3055


테스트 컨텍스트 클래스명 ‘…_20_characters’ → ‘…_50_characters’로 일관성 있게 수정 필요

아래 테스트 파일들에서 컨텍스트 클래스명이 아직 …_longer_than_20_characters로 남아 있으니, 새로 적용된 50자 제한에 맞춰 모두 변경해주세요.
메시지 문자열(Username must be between 1 and 20 characters)은 더 이상 남아 있지 않아 정상입니다.

  • src/test/java/com/nexters/teamace/user/application/CreateUserCommandTest.java:70
    class Context_when_creating_with_username_longer_than_20_characters
  • src/test/java/com/nexters/teamace/auth/application/SignupCommandTest.java:55
    class Context_when_creating_with_username_longer_than_20_characters
  • src/test/java/com/nexters/teamace/auth/application/LoginCommandTest.java:54
    class Context_when_creating_with_username_longer_than_20_characters
🤖 Prompt for AI Agents
In src/test/java/com/nexters/teamace/user/application/CreateUserCommandTest.java
around lines 69-79 (and similarly in
src/test/java/com/nexters/teamace/auth/application/SignupCommandTest.java around
line 55 and
src/test/java/com/nexters/teamace/auth/application/LoginCommandTest.java around
line 54), the inner test context class name still reads
Context_when_creating_with_username_longer_than_20_characters; rename these to
Context_when_creating_with_username_longer_than_50_characters (and update any
references/imports in those files) so the class names reflect the new
50-character username limit and remain consistent across tests.

}
}

Expand Down