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 @@ -12,8 +12,8 @@
import com.aloc.aloc.course.dto.response.CourseResponseDto;
import com.aloc.aloc.global.apipayload.CustomApiResponse;
import com.aloc.aloc.global.apipayload.status.SuccessStatus;
import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.service.ProfileBackgroundColorService;
import com.aloc.aloc.user.dto.response.ColorResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aloc.aloc.global.init;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aloc.aloc.user.dto.response;
package com.aloc.aloc.profilebackgroundcolor.dto.response;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aloc.aloc.profilebackgroundcolor;
package com.aloc.aloc.profilebackgroundcolor.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -8,6 +8,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

// 프로필 배경 색상 엔티티
// color1, color2, color3, color4, color5 : 색상 코드
// type : common, rare, special
// degree : CSS 그라데이션 각도, 135, 180을 주로 사용
@Entity
@Getter
@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.aloc.aloc.profilebackgroundcolor.repository;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

// 프로필 배경 색상 레포지토리

// 조회
// 1. findByName 이름으로 조회
// 2. findByType 타입으로 조회
@Repository
public interface ProfileBackgroundColorRepository
extends JpaRepository<ProfileBackgroundColor, String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.aloc.aloc.profilebackgroundcolor.service;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
import com.aloc.aloc.user.dto.response.ColorResponseDto;
import com.aloc.aloc.user.repository.UserRepository;
import java.util.List;
import java.util.Random;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

// 프로필 배경 색상 서비스
// 1. getColorByName 이름으로 조회
// 2. pickColor 랜덤 컬러 선택
// 3. getAllColors 모든 컬러 조회
@Service
@RequiredArgsConstructor
public class ProfileBackgroundColorService {
Expand All @@ -17,12 +21,18 @@ public class ProfileBackgroundColorService {

private static final int COLOR_CHANGE_MONEY = 100;

// 1. getColorByName 이름으로 조회
// input : 컬러 이름
// output : 컬러 이름에 해당하는 컬러
public ProfileBackgroundColor getColorByName(String name) {
return profileBackgroundColorRepository
.findByName(name)
.orElseThrow(() -> new IllegalArgumentException("해당 컬러가 없습니다. " + name));
}

// 2. pickColor 랜덤 컬러 선택
// input : 없음
// output : 랜덤 컬러 이름
public String pickColor() {
Random random = new Random();
int draw = random.nextInt(100) + 1;
Expand All @@ -41,6 +51,9 @@ public String pickColor() {
.getName();
}

// 3. getAllColors 모든 컬러 조회
// input : 없음
// output : 모든 컬러 리스트
public List<ColorResponseDto> getAllColors() {
return profileBackgroundColorRepository.findAll().stream().map(ColorResponseDto::of).toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aloc.aloc.user.dto.response;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aloc.aloc.user.dto.response;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.user.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/aloc/aloc/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aloc.aloc.user.service;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
import com.aloc.aloc.profilebackgroundcolor.service.ProfileBackgroundColorService;
import com.aloc.aloc.scraper.BaekjoonRankScrapingService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aloc.aloc.user.service.mapper;

import com.aloc.aloc.profilebackgroundcolor.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.service.ProfileBackgroundColorService;
import com.aloc.aloc.user.dto.response.UserDetailResponseDto;
import com.aloc.aloc.user.entity.User;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/aloc/aloc/AlocApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
class AlocApplicationTests {
Comment on lines +5 to 9
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

테스트 프로필 활성화 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 || true

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 연결 설정 추가
  • H2 의존성(com.h2database:h2)은 build.gradle 74행에 선언되어 있음 → 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.


@Test
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/com/aloc/aloc/common/fixture/TestFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.aloc.aloc.problem.dto.response.ProblemSolvedResponseDto;
import com.aloc.aloc.problem.entity.Problem;
import com.aloc.aloc.problem.enums.UserCourseProblemStatus;
import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.user.dto.response.UserDetailResponseDto;
import com.aloc.aloc.user.entity.User;
import com.aloc.aloc.user.enums.Authority;
Expand Down Expand Up @@ -143,4 +145,50 @@ public static UserCourseProblem getMockUserCourseProblem(
.problemOrder(problemOrder)
.build();
}

// ProfileBackgroundColor 관련 테스트 픽스처
public static ProfileBackgroundColor getMockProfileBackgroundColor() {
return ProfileBackgroundColor.builder()
.name("TestColor")
.color1("#0000FF")
.color2("#87CEEB")
.color3(null)
.color4(null)
.color5(null)
.type("common")
.degree(135)
.build();
}

public static ProfileBackgroundColor getMockProfileBackgroundColorByType(String type) {
return ProfileBackgroundColor.builder()
.name("Test" + type)
.color1("#FF0000")
.color2("#00FF00")
.color3("#0000FF")
.color4(null)
.color5(null)
.type(type)
.degree(180)
.build();
}

public static ProfileBackgroundColor getMockProfileBackgroundColorByName(
String name, String type) {
return ProfileBackgroundColor.builder()
.name(name)
.color1("#FF5A5A")
.color2("#FFB800")
.color3(null)
.color4(null)
.color5(null)
.type(type)
.degree(135)
.build();
}

public static ColorResponseDto getMockColorResponseDto() {
ProfileBackgroundColor color = getMockProfileBackgroundColor();
return ColorResponseDto.of(color);
}
}
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
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
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.

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
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

@mock UserRepository 누락

ProfileBackgroundColorServiceProfileBackgroundColorRepositoryUserRepository 두 개의 의존성을 생성자에서 받습니다. @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.


// [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);
}
}