-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: 대학(추천, 좋아요) 통합 테스트 데이터 Fixture 메서드로 변경 #313
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
Merged
Gyuhyeok99
merged 2 commits into
solid-connection:develop
from
Gyuhyeok99:refactor/312-university-test-fixture-module
May 12, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,15 @@ | |
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.siteuser.repository.LikedUniversityRepository; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.support.integration.BaseIntegrationTest; | ||
| import com.example.solidconnection.support.TestContainerSpringBootTest; | ||
| import com.example.solidconnection.type.PreparationStatus; | ||
| import com.example.solidconnection.type.Role; | ||
| import com.example.solidconnection.university.domain.LikedUniversity; | ||
| import com.example.solidconnection.university.domain.UniversityInfoForApply; | ||
| import com.example.solidconnection.university.dto.IsLikeResponse; | ||
| import com.example.solidconnection.university.dto.LikeResultResponse; | ||
| import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -25,8 +27,9 @@ | |
| import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; | ||
| import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
|
||
| @TestContainerSpringBootTest | ||
| @DisplayName("대학교 좋아요 서비스 테스트") | ||
| class UniversityLikeServiceTest extends BaseIntegrationTest { | ||
| class UniversityLikeServiceTest { | ||
|
|
||
| @Autowired | ||
| private UniversityLikeService universityLikeService; | ||
|
|
@@ -37,14 +40,23 @@ class UniversityLikeServiceTest extends BaseIntegrationTest { | |
| @Autowired | ||
| private SiteUserRepository siteUserRepository; | ||
|
|
||
| @Autowired | ||
| private UniversityInfoForApplyFixture universityInfoForApplyFixture; | ||
|
|
||
| private SiteUser testUser; | ||
| private UniversityInfoForApply 괌대학_A_지원_정보; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| testUser = createSiteUser(); | ||
| 괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보(); | ||
| } | ||
|
Comment on lines
+49
to
+53
Collaborator
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. BeforeEach 좋네요😊 |
||
|
|
||
| @Nested | ||
| class 대학_좋아요를_등록한다 { | ||
|
|
||
| @Test | ||
| void 성공적으로_좋아요를_등록한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
|
|
||
| // when | ||
| LikeResultResponse response = universityLikeService.likeUniversity(testUser, 괌대학_A_지원_정보.getId()); | ||
|
|
||
|
|
@@ -60,7 +72,6 @@ class 대학_좋아요를_등록한다 { | |
| @Test | ||
| void 이미_좋아요한_대학이면_예외_응답을_반환한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
| saveLikedUniversity(testUser, 괌대학_A_지원_정보); | ||
|
|
||
| // when & then | ||
|
|
@@ -76,7 +87,6 @@ class 대학_좋아요를_취소한다 { | |
| @Test | ||
| void 성공적으로_좋아요를_취소한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
| saveLikedUniversity(testUser, 괌대학_A_지원_정보); | ||
|
|
||
| // when | ||
|
|
@@ -93,9 +103,6 @@ class 대학_좋아요를_취소한다 { | |
|
|
||
| @Test | ||
| void 좋아요하지_않은_대학이면_예외_응답을_반환한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> universityLikeService.cancelLikeUniversity(testUser, 괌대학_A_지원_정보.getId())) | ||
| .isInstanceOf(CustomException.class) | ||
|
|
@@ -106,7 +113,6 @@ class 대학_좋아요를_취소한다 { | |
| @Test | ||
| void 존재하지_않는_대학_좋아요_시도하면_예외_응답을_반환한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
| Long invalidUniversityId = 9999L; | ||
|
|
||
| // when & then | ||
|
|
@@ -118,7 +124,6 @@ class 대학_좋아요를_취소한다 { | |
| @Test | ||
| void 좋아요한_대학인지_확인한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
| saveLikedUniversity(testUser, 괌대학_A_지원_정보); | ||
|
|
||
| // when | ||
|
|
@@ -130,9 +135,6 @@ class 대학_좋아요를_취소한다 { | |
|
|
||
| @Test | ||
| void 좋아요하지_않은_대학인지_확인한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
|
|
||
| // when | ||
| IsLikeResponse response = universityLikeService.getIsLiked(testUser, 괌대학_A_지원_정보.getId()); | ||
|
|
||
|
|
@@ -143,7 +145,6 @@ class 대학_좋아요를_취소한다 { | |
| @Test | ||
| void 존재하지_않는_대학의_좋아요_여부를_조회하면_예외_응답을_반환한다() { | ||
| // given | ||
| SiteUser testUser = createSiteUser(); | ||
| Long invalidUniversityId = 9999L; | ||
|
|
||
| // when & then | ||
|
|
@@ -152,6 +153,7 @@ class 대학_좋아요를_취소한다 { | |
| .hasMessage(UNIVERSITY_INFO_FOR_APPLY_NOT_FOUND.getMessage()); | ||
| } | ||
|
|
||
| // todo : 추후 Fixture로 대체 필요 | ||
|
Collaborator
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. todo로 앞으로의 계획 표시 좋습니다! 🤩 |
||
| private SiteUser createSiteUser() { | ||
| SiteUser siteUser = new SiteUser( | ||
| "test@example.com", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
혹시 다시 확인해주실 수 있나요? 😲
제가 break point 찍어서 확인해봤을 때는 generalUniversityRecommendService.init() 호출 전에
테스트 데이터가 0개이면,
에서 universities는 비어있는 리스트가 됩니다.
out of range 예외는 발생하지 않고요!
그리고 데이터베이스에 대학 지원 정보가 6개보다 적은 "2개"만 있더라도,
out of range 예외는 발생하지 않고, "크기가 2인 리스트"가 반환됩니다.
말씀하신 부분은 이미 구현되어있습니다~
제가 테스트를 모호하게 작성한게 있어 이런 오해가 발생했으니,
“목표 추천 대학보다 적은 수의 대학이 들어있다면 그만큼을 반환한다” 는 것을 검증하는 테스트 코드를 추가하여 여러가지 케이스를 보여주도록 할 필요는 있어보입니다.
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.
아 제가 조금 명확하게 말씀을 안드렸네요...
UniversityRecommendService에서 getGeneralRecommendsExcludingSelected 함수가 있는데
여기서 문제가 발생하는 거 같습니다
예시로 alreadyPicked.size()이라는 맞춤 추천 대학 개수가 2개로 가지고 있으면 부족한 개수를 이번 term에 열리는 학교들을 불러오고 있습니다. return으로 결국 subList(0, 4)를 호출하게 되는데 이때 말씀해주신 universities 에 3개의 대학만 들어가있다면 IndexOutOfBoundsException를 발생시킵니다!
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.
아하 "General" UniversityRecommendService의 테스트 코드가 아니라
UniversityRecommendService의 테스트코드 말씀이셨군요!
저는 뭔가가 잘못된건가.. 했습니다😅