-
Notifications
You must be signed in to change notification settings - Fork 0
233 feat profile background color test code #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
233 feat profile background color test code #225
Conversation
Walkthrough이번 변경은 Changes
Sequence Diagram(s)sequenceDiagram
participant Test as ProfileBackgroundColorServiceTest
participant Service as ProfileBackgroundColorService
participant Repo as ProfileBackgroundColorRepository
Test->>Service: getColorByName("colorName")
Service->>Repo: findByName("colorName")
alt 색상 존재
Repo-->>Service: Optional.of(ProfileBackgroundColor)
Service-->>Test: ProfileBackgroundColor 반환
else 색상 없음
Repo-->>Service: Optional.empty()
Service-->>Test: IllegalArgumentException 발생
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10분 Possibly related PRs
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🔭 Outside diff range comments (4)
src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java (1)
57-59: 빈 문자열("") 대신 null 사용으로 의미를 통일하세요일부 색상에서 color4, color5를 ""로 넣고 있습니다. 다른 항목은 null을 사용하고 있어 의미가 혼재됩니다. 직렬화/DTO 매핑/프론트 처리에서 혼란을 줄이려면 null로 통일하는 것을 권장합니다.
제안 diff:
- new ProfileBackgroundColor( - "BeautifulYPB", "#FFB800", "#FF69F0", "#408CFF", "", "", "special", 135), + new ProfileBackgroundColor( + "BeautifulYPB", "#FFB800", "#FF69F0", "#408CFF", null, null, "special", 135), - new ProfileBackgroundColor( - "BeautifulBPR", "#408CFF", "#E95FFF", "#FF5A5A", "", "", "special", 135), + new ProfileBackgroundColor( + "BeautifulBPR", "#408CFF", "#E95FFF", "#FF5A5A", null, null, "special", 135),src/main/java/com/aloc/aloc/user/dto/response/UserDetailResponseDto.java (1)
40-41: UserDetailResponseDto 색상 NPE 처리 필요프로필 색상이 아직 설정되지 않은 경우
ColorResponseDto.of(profileBackgroundColor)호출 시 NPE가 발생할 수 있습니다. 아래와 같이 null-safe 매핑을 적용하거나, null 불허 설계라면 파라미터에 @nonnull을 부여해 조기 실패를 도입하세요.
- 대상: src/main/java/com/aloc/aloc/user/dto/response/UserDetailResponseDto.java (40–41행)
- .color(ColorResponseDto.of(profileBackgroundColor)) + .color(profileBackgroundColor != null + ? ColorResponseDto.of(profileBackgroundColor) + : null)null 불허 설계 시 예시:
public static UserDetailResponseDto of( @NonNull User user, @NonNull ProfileBackgroundColor profileBackgroundColor, boolean isTodaySolved ) { … }src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (2)
20-20: 미사용 의존성 제거 제안: UserRepository
UserRepository필드가 현재 클래스 내에서 사용되지 않습니다. 불필요한 의존성은 유지보수성과 가독성을 떨어뜨립니다. 제거를 권장합니다.가능한 변경 예시:
- private final UserRepository userRepository;(주의: 제거 시 해당 import도 함께 정리해 주세요.)
36-52: 빈 결과 처리 및 난수 생성기 개선이 필요합니다
- type별 조회 결과가 빈 리스트일 때
random.nextInt(0)로IllegalArgumentException이 발생할 수 있습니다.ThreadLocalRandom사용이 가볍고 스레드-세이프합니다.다음과 같이 리팩터를 제안합니다.
- public String pickColor() { - Random random = new Random(); - int draw = random.nextInt(100) + 1; - - List<ProfileBackgroundColor> profileBackgroundColorList; - if (draw <= 85) { - profileBackgroundColorList = profileBackgroundColorRepository.findByType("common"); - } else if (draw <= 95) { - profileBackgroundColorList = profileBackgroundColorRepository.findByType("rare"); - } else { - profileBackgroundColorList = profileBackgroundColorRepository.findByType("special"); - } - - return profileBackgroundColorList - .get(random.nextInt(profileBackgroundColorList.size())) - .getName(); - } + public String pickColor() { + int draw = java.util.concurrent.ThreadLocalRandom.current().nextInt(1, 101); + + String type; + if (draw <= 85) { + type = "common"; + } else if (draw <= 95) { + type = "rare"; + } else { + type = "special"; + } + + List<ProfileBackgroundColor> colors = profileBackgroundColorRepository.findByType(type); + if (colors == null || colors.isEmpty()) { + throw new IllegalStateException("해당 타입의 컬러가 존재하지 않습니다: " + type); + } + + int idx = java.util.concurrent.ThreadLocalRandom.current().nextInt(colors.size()); + return colors.get(idx).getName(); + }
🧹 Nitpick comments (11)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
11-14: 엔티티 설명은 Javadoc/제약으로 “문서화가 아닌 컴파일 타임”에 강제하는 것을 권장주석은 좋지만, 아래와 같이 스키마/검증으로 제약을 명시하면 안전합니다.
- type은 문자열 대신 Enum + @Enumerated(EnumType.STRING) 사용 권장
- color1~5는 HEX 컬러 형태를 @pattern으로 검증 권장
- color2~5의 “없음” 표현은 null/"" 혼재 대신 하나로 통일 (DevDataInitializer에서 "" 사용 중)
- degree는 기본값(예: 135) 지정 또는 허용 범위 검증(@Min/@max) 고려
예시:
public enum ProfileColorType { COMMON, RARE, SPECIAL } @Entity public class ProfileBackgroundColor { @Id private String name; @NotBlank @Pattern(regexp = "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") private String color1; @Pattern(regexp = "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") private String color2; // color3~5 동일 패턴 적용 @Enumerated(EnumType.STRING) @Column(nullable = false) private ProfileColorType type; @Min(0) @Max(360) private Integer degree; }src/main/java/com/aloc/aloc/user/service/mapper/UserMapper.java (1)
25-34: 시간 비교는 Clock 주입으로 테스트 가능성과 타임존 안정성을 높이세요LocalDate.now() 직접 호출 대신 Clock 주입을 권장합니다. 재현성 있는 테스트와 서버 타임존 변화에 안전합니다.
예시:@Component @RequiredArgsConstructor public class UserMapper { private final Clock clock; private boolean isTodaySolved(LocalDateTime lastSolvedAt) { if (lastSolvedAt == null) return false; LocalDate today = LocalDate.now(clock); return lastSolvedAt.toLocalDate().isEqual(today); } }src/main/java/com/aloc/aloc/user/service/UserService.java (1)
125-127: orElseThrow에 명시적 예외 메시지 추가 제안디버깅 편의성을 위해 메시지를 포함하세요.
- ProfileBackgroundColor profileBackgroundColor = - profileBackgroundColorRepository.findById(colorName).orElseThrow(); + ProfileBackgroundColor profileBackgroundColor = + profileBackgroundColorRepository + .findById(colorName) + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 색상입니다: " + colorName));src/main/java/com/aloc/aloc/user/dto/response/UserDetailResponseDto.java (1)
26-27: 불리언 필드 네이밍 개선 제안(직렬화 호환성).
private boolean isTodaySolved;는 Lombok/Jackson 조합에서 게터/프로퍼티명이 혼동될 수 있습니다. 다음 중 하나를 권장합니다:
- 필드명을
todaySolved로 변경(권장), 또는@JsonProperty("isTodaySolved")명시API 스키마 호환성에 영향이 있으니 변경 시 컨트롤러/문서/클라이언트 점검을 권장합니다.
src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java (1)
11-15: 일관성: 다른 필드가 final인 만큼 name도 final 고려.현재
name만 가변이고 나머지는 final입니다. DTO 불변성 관점에서name도 final로 맞추면 일관성이 좋아집니다. 호환성 영향이 없다면 반영을 추천합니다.src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java (2)
9-13: 주석 형식 개선 제안(가독성).라인 주석 대신 Javadoc으로 요약을 상단에 부여하면 IDE/문서화에 유리합니다. 예:
-// 프로필 배경 색상 레포지토리 -// 조회 -// 1. findByName 이름으로 조회 -// 2. findByType 타입으로 조회 +/** + * 프로필 배경 색상 레포지토리 + * - findByName: 이름으로 조회 + * - findByType: 타입으로 조회 + */
19-19: 조회 패턴 최적화(인덱스 권장).
findByType빈도가 높다면 DB에 type 컬럼 인덱스를 추가하세요. 엔티티에 아래와 같이 선언 가능:// src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java @Table(indexes = @Index(name = "idx_profile_background_color_type", columnList = "type"))src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (2)
22-22: 미사용 상수 제거
COLOR_CHANGE_MONEY상수가 사용되지 않습니다. 불필요한 상수는 제거해 주세요.- private static final int COLOR_CHANGE_MONEY = 100;
57-59: toList 사용 시 Java 버전 확인 필요
Stream#toList()는 Java 16+에서 지원됩니다. 프로젝트 기준 Java 버전이 11/8이라면Collectors.toList()로의 교체가 필요합니다.대안:
return profileBackgroundColorRepository.findAll() .stream() .map(ColorResponseDto::of) .collect(java.util.stream.Collectors.toList());src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java (2)
30-52: 정상 케이스 테스트 적절의존성 Stub, 반환값 검증, 상호작용 검증이 간결하고 명확합니다. 동일 인스턴스 반환을
isEqualTo로 확인하는 것도 현재 구현에 부합합니다.중복 단언을 줄이려면
usingRecursiveComparison()도 고려할 수 있습니다.
54-69: 예외 케이스 테스트 적절메시지까지 검증해 회귀를 방지합니다. 상호작용 검증도 적절합니다.
추가로, null/blank 이름에 대한 방어 로직이 서비스에 추가된다면 해당 경우의 테스트도 보강해 주세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/main/java/com/aloc/aloc/admin/controller/AdminController.java(1 hunks)src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java(1 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java(1 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java(2 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java(1 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java(3 hunks)src/main/java/com/aloc/aloc/user/dto/response/UserColorChangeResponseDto.java(1 hunks)src/main/java/com/aloc/aloc/user/dto/response/UserDetailResponseDto.java(1 hunks)src/main/java/com/aloc/aloc/user/service/UserService.java(1 hunks)src/main/java/com/aloc/aloc/user/service/mapper/UserMapper.java(1 hunks)src/test/java/com/aloc/aloc/AlocApplicationTests.java(1 hunks)src/test/java/com/aloc/aloc/common/fixture/TestFixture.java(2 hunks)src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
src/main/java/com/aloc/aloc/user/service/mapper/UserMapper.java (2)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (1)
ColorResponseDto(8-47)
src/main/java/com/aloc/aloc/admin/controller/AdminController.java (2)
src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (2)
ColorResponseDto(8-47)of(35-46)src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)
src/main/java/com/aloc/aloc/user/service/UserService.java (2)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (1)
ColorResponseDto(8-47)
src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java (1)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)
src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java (2)
src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (2)
ColorResponseDto(8-47)of(35-46)src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)
src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (2)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (1)
ColorResponseDto(8-47)
src/test/java/com/aloc/aloc/common/fixture/TestFixture.java (2)
src/main/java/com/aloc/aloc/user/dto/response/ColorResponseDto.java (2)
ColorResponseDto(8-47)of(35-46)src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)
src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java (2)
src/main/java/com/aloc/aloc/profilebackgroundcolor/ProfileBackgroundColor.java (1)
ProfileBackgroundColor(11-32)src/test/java/com/aloc/aloc/user/service/UserServiceTest.java (1)
UserServiceTest(17-51)
🔇 Additional comments (18)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
1-1: 패키지 이동 반영 LGTM패키지 구조 정리는 일관성/가독성 측면에서 좋습니다. 관련 import 일괄 변경도 함께 확인 부탁드립니다.
src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java (1)
3-3: 엔티티 패키지 경로 변경 반영 LGTM초기 데이터 생성 로직에는 영향이 없으며, 리팩토링 방향과 일치합니다.
src/main/java/com/aloc/aloc/user/service/mapper/UserMapper.java (1)
3-3: 엔티티 import 경로 변경 LGTM리팩토링된 패키지 구조와 일치합니다.
src/main/java/com/aloc/aloc/user/service/UserService.java (1)
3-3: 엔티티 import 경로 변경 LGTM전체 구조 리팩토링과 일관됩니다.
src/main/java/com/aloc/aloc/admin/controller/AdminController.java (1)
15-15: ColorResponseDto 패키지 이동 반영 LGTMDTO 책임을 profilebackgroundcolor 모듈로 이동한 방향이 적절합니다. 컨트롤러 시그니처와도 일치합니다.
src/main/java/com/aloc/aloc/user/dto/response/UserDetailResponseDto.java (1)
3-4: 레이어 분리 방향 적절합니다 (DTO 노출).엔티티 대신 ColorResponseDto를 의존하도록 import를 정리해 응답 계층 누수를 방지했습니다. 변경 취지와 일치하며 LGTM입니다.
src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java (2)
1-3: 패키지/의존성 정리 👍패키지 이동 및 엔티티 import 경로 수정이 일관성 있게 반영되었습니다. LGTM입니다.
35-46: 추가 정보가 필요합니다. 현재 다른 DTOof()메서드들이@NonNull을 사용하고 있는지, 또는 null 체크를 전역적으로 적용하고 있는지를 확인해야 합니다. 예를 들어, 다른of(...)메서드에@NonNull어노테이션이 있는지 검색해 주세요.src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java (1)
3-3: 엔티티 import 경로 수정 LGTM.패키지 분리와 일관되게 entity 서브패키지를 참조하도록 수정된 점 적절합니다.
src/main/java/com/aloc/aloc/user/dto/response/UserColorChangeResponseDto.java (2)
3-4: DTO 분리 적용 👍응답에서 엔티티 대신 ColorResponseDto를 노출하도록 import를 정리한 점 적절합니다. LGTM.
21-26: NPE 우려 불필요: orElseThrow로 null 불가능
DB 조회 로직(findById(colorName).orElseThrow())이 프로필 색상이 없을 경우 예외를 던져of()호출 시profileBackgroundColor에 null이 전달되지 않습니다. 따라서 null 검사나@NonNull선언은 불필요합니다.Likely an incorrect or invalid review comment.
src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (2)
3-4: ColorResponseDto import 경로 재확인 필요제공된 관련 스니펫에서는 ColorResponseDto가
com.aloc.aloc.user.dto.response패키지로 보입니다. 현재 파일은com.aloc.aloc.profilebackgroundcolor.dto.response에서 import 중입니다. 패키지 리팩터링 결과와 실제 파일 위치가 일치하는지 확인 부탁드립니다. 경로 불일치 시 컴파일 실패가 납니다.다음 스크립트로 실제 선언 패키지를 확인해 주세요.
#!/bin/bash echo "== ColorResponseDto 위치 및 package 라인 ==" fd -a "ColorResponseDto.java" | while read -r f; do echo "FILE: $f" rg -n "^package " -n "$f" done echo echo "== Service 파일의 import 라인 확인 ==" rg -n "import .*ColorResponseDto" src/main/java | sed -n '1,120p' echo echo "== ProfileBackgroundColor 엔티티 위치 및 package 라인 ==" fd -a "ProfileBackgroundColor.java" | while read -r f; do echo "FILE: $f" rg -n "^package " -n "$f" doneLikely an incorrect or invalid review comment.
27-31: getColorByName 동작 적정존재하지 않는 색상에 대해 명확한 메시지로
IllegalArgumentException을 발생시키는 흐름이 적절합니다.src/test/java/com/aloc/aloc/common/fixture/TestFixture.java (5)
14-16: DTO/엔티티 import 경로 확인ColorResponseDto/ProfileBackgroundColor의 실제 패키지 경로가 리팩터링 결과와 일치하는지 확인이 필요합니다. 제공 스니펫과 경로가 상이할 수 있습니다.
검증 스크립트:
#!/bin/bash echo "== ColorResponseDto 위치 및 package 라인 ==" fd -a "ColorResponseDto.java" | while read -r f; do echo "FILE: $f" rg -n "^package " -n "$f" done echo echo "== ProfileBackgroundColor 위치 및 package 라인 ==" fd -a "ProfileBackgroundColor.java" | while read -r f; do echo "FILE: $f" rg -n "^package " -n "$f" doneLikely an incorrect or invalid review comment.
149-161: 기본 ProfileBackgroundColor 픽스처 LGTM필드 조합과 null 허용 컬럼 사용이 합리적입니다. 테스트 전반에 재사용하기 좋습니다.
163-174: 타입 가변 픽스처 LGTMtype에 따른 이름/색상 분기 생성에 유용합니다.
176-188: 이름/타입 가변 픽스처 LGTM이름과 타입을 동시에 제어할 수 있어 시나리오 작성에 적절합니다.
190-193: ColorResponseDto 변환 픽스처 LGTM엔티티→DTO 변환 경로를 고정해 일관된 데이터 생성에 적합합니다. 상위 import 경로만 확인되면 문제 없습니다.
| import org.springframework.test.context.ActiveProfiles; | ||
|
|
||
| @SpringBootTest | ||
| @ActiveProfiles("test") | ||
| class AlocApplicationTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
테스트 프로필 활성화 LGTM — H2/프로퍼티 존재 여부 확인 권장.
@activeprofiles("test") 추가로 CI 독립성이 개선됩니다. 아래 스크립트로 테스트 프로필 파일·H2 의존성·DB URL을 확인해 주세요.
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "1) test 프로필 설정 파일 존재 여부"
fd -a application-test -e yml -e yaml -e properties || true
echo
echo "2) H2 메모리 DB URL 사용 여부"
rg -n "jdbc:h2:mem" || true
echo
echo "3) H2 의존성 선언 여부 (Gradle/Maven 모두 탐색)"
rg -n "com\.h2database" || true
echo
echo "4) 다른 테스트가 상이한 프로필을 강제하지 않는지 확인"
rg -n '@ActiveProfiles\(".*"\)' src/test || trueLength of output: 593
테스트 프로필 파일 및 H2 메모리 DB 설정 추가 필요
테스트용 프로필 파일과 메모리 DB URL 설정이 없어 CI 독립성이 보장되지 않습니다. 아래 사항을 반영해주세요.
application-test.yml또는application-test.properties파일이 존재하지 않음
→src/test/resources/에 신규 생성jdbc:h2:mem:URL 미사용
→ test 프로필에서 H2 인메모리 DB 연결 설정 추가- H2 의존성(
com.h2database:h2)은build.gradle74행에 선언되어 있음 → OK - 다른 테스트 클래스에
@ActiveProfiles지정 사례 없음 → OK
src/test/resources/application-test.yml(또는 .properties)를 생성하여 아래와 같이 H2 메모리 DB 설정을 추가해주세요.
🤖 Prompt for AI Agents
In src/test/java/com/aloc/aloc/AlocApplicationTests.java around lines 5 to 9,
the test profile and H2 in-memory database configuration are missing, which
affects CI independence. Create a new test profile configuration file named
application-test.yml or application-test.properties under src/test/resources/.
In this file, add the necessary settings to connect to the H2 in-memory database
using the jdbc:h2:mem: URL. This will ensure the tests run with an isolated
in-memory database environment when the "test" profile is active.
| import com.aloc.aloc.common.fixture.TestFixture; | ||
| import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor; | ||
| import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository; | ||
| import java.util.Optional; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserRepository import 추가 필요 (테스트 주입 실패 방지)
Service는 생성자에서 UserRepository도 요구합니다. 테스트에서 해당 타입의 @mock을 제공하지 않으면 @InjectMocks 인스턴스 생성에 실패할 수 있습니다. import를 추가해 주세요.
import com.aloc.aloc.common.fixture.TestFixture;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
+import com.aloc.aloc.user.repository.UserRepository;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import com.aloc.aloc.common.fixture.TestFixture; | |
| import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor; | |
| import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository; | |
| import java.util.Optional; | |
| import com.aloc.aloc.common.fixture.TestFixture; | |
| import com.aloc.aloc.profilebackgroundcolor.entity/ProfileBackgroundColor; | |
| import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository; | |
| import com.aloc.aloc.user.repository.UserRepository; | |
| import java.util.Optional; |
🤖 Prompt for AI Agents
In
src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java
around lines 8 to 11, the import statement for UserRepository is missing. Add
the import for UserRepository to ensure the test class can properly mock and
inject this dependency, preventing failures during the creation of the
@InjectMocks instance in the test setup.
| @Mock private ProfileBackgroundColorRepository profileBackgroundColorRepository; | ||
|
|
||
| @InjectMocks private ProfileBackgroundColorService profileBackgroundColorService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mock UserRepository 누락
ProfileBackgroundColorService는 ProfileBackgroundColorRepository와 UserRepository 두 개의 의존성을 생성자에서 받습니다. @Mock UserRepository가 누락되어 있어 @InjectMocks 인스턴스 생성이 실패할 가능성이 큽니다.
다음과 같이 필드를 추가해 주세요.
@Mock private ProfileBackgroundColorRepository profileBackgroundColorRepository;
+ @Mock private UserRepository userRepository;
+
@InjectMocks private ProfileBackgroundColorService profileBackgroundColorService;🤖 Prompt for AI Agents
In
src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java
around lines 25 to 27, the test class is missing a @Mock annotation for
UserRepository, which is a required dependency for ProfileBackgroundColorService
constructor. Add a private field annotated with @Mock for UserRepository to
ensure that @InjectMocks can properly create the ProfileBackgroundColorService
instance without errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM😎
📌 PR 제목
profileBackgroundColor TestCode 추가
✅ 작업 내용
1. ProfileBackgroundColor 테스트 코드 구현
ProfileBackgroundColorServiceTest.java 생성
getColorByName() 정상 케이스 테스트
getColorByName() 예외 케이스 테스트 (존재하지 않는 색상)
Mockito 기반 단위 테스트 구현
2. TestFixture 확장
ProfileBackgroundColor 관련 Mock 데이터 생성 메서드 추가:
getMockProfileBackgroundColor()
getMockProfileBackgroundColorByType(String type)
getMockProfileBackgroundColorByName(String name, String type)
getMockColorResponseDto()
3. 테스트 환경 설정 개선
AlocApplicationTests.java에 @activeprofiles("test") 추가
H2 인메모리 데이터베이스 사용으로 테스트 독립성 확보
PostgreSQL 의존성 제거로 CI/CD 환경에서 안정적인 테스트 실행
4. 기존 코드 보완
ProfileBackgroundColor 관련 엔티티, 서비스, DTO 코드 개선
User와 ProfileBackgroundColor 연동 부분 수정
Summary by CodeRabbit
문서화
테스트