-
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
Changes from all commits
80cd71f
b11a61b
8db77d4
4d1e7b0
4e8d441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||||||
| package com.aloc.aloc.profilebackgroundcolor.service; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||||||||||||||||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||||||||||||||||||||
| import static org.mockito.BDDMockito.given; | ||||||||||||||||||||
| import static org.mockito.Mockito.verify; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 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; | ||||||||||||||||||||
|
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserRepository import 추가 필요 (테스트 주입 실패 방지) Service는 생성자에서 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||
| import org.junit.jupiter.api.extension.ExtendWith; | ||||||||||||||||||||
| import org.mockito.InjectMocks; | ||||||||||||||||||||
| import org.mockito.Mock; | ||||||||||||||||||||
| import org.mockito.junit.jupiter.MockitoExtension; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // 테스트 함수 목록 | ||||||||||||||||||||
| // [getColorByName] 정상 케이스 - 존재하는 색상 이름으로 조회 | ||||||||||||||||||||
| // [getColorByName] 예외 케이스 - 존재하지 않는 색상 이름으로 조회 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @ExtendWith(MockitoExtension.class) | ||||||||||||||||||||
| public class ProfileBackgroundColorServiceTest { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Mock private ProfileBackgroundColorRepository profileBackgroundColorRepository; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @InjectMocks private ProfileBackgroundColorService profileBackgroundColorService; | ||||||||||||||||||||
|
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mock UserRepository 누락
다음과 같이 필드를 추가해 주세요. @Mock private ProfileBackgroundColorRepository profileBackgroundColorRepository;
+ @Mock private UserRepository userRepository;
+
@InjectMocks private ProfileBackgroundColorService profileBackgroundColorService;🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| // [getColorByName] 정상 케이스 - 존재하는 색상 이름으로 조회 | ||||||||||||||||||||
| @Test | ||||||||||||||||||||
| void getColorByNameNormalCase() { | ||||||||||||||||||||
| // given | ||||||||||||||||||||
| String colorName = "TestColor"; | ||||||||||||||||||||
| ProfileBackgroundColor expectedColor = TestFixture.getMockProfileBackgroundColor(); | ||||||||||||||||||||
| given(profileBackgroundColorRepository.findByName(colorName)) | ||||||||||||||||||||
| .willReturn(Optional.of(expectedColor)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // when | ||||||||||||||||||||
| ProfileBackgroundColor result = profileBackgroundColorService.getColorByName(colorName); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // then | ||||||||||||||||||||
| assertThat(result).isEqualTo(expectedColor); | ||||||||||||||||||||
| assertThat(result.getName()).isEqualTo(colorName); | ||||||||||||||||||||
| assertThat(result.getType()).isEqualTo(expectedColor.getType()); | ||||||||||||||||||||
| assertThat(result.getColor1()).isEqualTo(expectedColor.getColor1()); | ||||||||||||||||||||
| assertThat(result.getColor2()).isEqualTo(expectedColor.getColor2()); | ||||||||||||||||||||
| assertThat(result.getColor3()).isEqualTo(expectedColor.getColor3()); | ||||||||||||||||||||
| assertThat(result.getColor4()).isEqualTo(expectedColor.getColor4()); | ||||||||||||||||||||
| assertThat(result.getColor5()).isEqualTo(expectedColor.getColor5()); | ||||||||||||||||||||
| assertThat(result.getDegree()).isEqualTo(expectedColor.getDegree()); | ||||||||||||||||||||
| verify(profileBackgroundColorRepository).findByName(colorName); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // [getColorByName] 예외 케이스 - 존재하지 않는 색상 이름으로 조회 | ||||||||||||||||||||
| @Test | ||||||||||||||||||||
| void getColorByNameExceptionCase() { | ||||||||||||||||||||
| // given | ||||||||||||||||||||
| String nonExistentColorName = "NonExistentColor"; | ||||||||||||||||||||
| given(profileBackgroundColorRepository.findByName(nonExistentColorName)) | ||||||||||||||||||||
| .willReturn(Optional.empty()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // when | ||||||||||||||||||||
| assertThatThrownBy(() -> profileBackgroundColorService.getColorByName(nonExistentColorName)) | ||||||||||||||||||||
| .isInstanceOf(IllegalArgumentException.class) | ||||||||||||||||||||
| .hasMessage("해당 컬러가 없습니다. " + nonExistentColorName); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // then | ||||||||||||||||||||
| verify(profileBackgroundColorRepository).findByName(nonExistentColorName); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
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:
Length of output: 593
테스트 프로필 파일 및 H2 메모리 DB 설정 추가 필요
테스트용 프로필 파일과 메모리 DB URL 설정이 없어 CI 독립성이 보장되지 않습니다. 아래 사항을 반영해주세요.
application-test.yml또는application-test.properties파일이 존재하지 않음→
src/test/resources/에 신규 생성jdbc:h2:mem:URL 미사용→ test 프로필에서 H2 인메모리 DB 연결 설정 추가
com.h2database:h2)은build.gradle74행에 선언되어 있음 → OK@ActiveProfiles지정 사례 없음 → OKsrc/test/resources/application-test.yml(또는.properties)를 생성하여 아래와 같이 H2 메모리 DB 설정을 추가해주세요.🤖 Prompt for AI Agents