Skip to content

Commit f3476fb

Browse files
committed
test: 바뀐 로직을 테스트 코드에 반영
1 parent 303ee8d commit f3476fb

File tree

1 file changed

+107
-162
lines changed

1 file changed

+107
-162
lines changed
Lines changed: 107 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.example.solidconnection.university.service;
22

33
import static com.example.solidconnection.common.exception.ErrorCode.UNIV_APPLY_INFO_NOT_FOUND;
4+
import static com.example.solidconnection.university.domain.LanguageTestType.TOEIC;
45
import static org.assertj.core.api.Assertions.assertThat;
56
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
7+
import static org.junit.jupiter.api.Assertions.assertAll;
68
import static org.mockito.BDDMockito.then;
79
import static org.mockito.Mockito.times;
810

911
import com.example.solidconnection.common.exception.CustomException;
1012
import com.example.solidconnection.support.TestContainerSpringBootTest;
11-
import com.example.solidconnection.university.domain.LanguageTestType;
1213
import com.example.solidconnection.university.domain.UnivApplyInfo;
1314
import com.example.solidconnection.university.dto.UnivApplyInfoDetailResponse;
15+
import com.example.solidconnection.university.dto.UnivApplyInfoFilterSearchRequest;
1416
import com.example.solidconnection.university.dto.UnivApplyInfoPreviewResponse;
1517
import com.example.solidconnection.university.dto.UnivApplyInfoPreviewResponses;
1618
import com.example.solidconnection.university.fixture.LanguageRequirementFixture;
1719
import com.example.solidconnection.university.fixture.UnivApplyInfoFixture;
1820
import com.example.solidconnection.university.repository.UnivApplyInfoRepository;
19-
import com.example.solidconnection.university.repository.custom.UnivApplyInfoFilterRepository;
2021
import java.util.List;
2122
import org.junit.jupiter.api.DisplayName;
23+
import org.junit.jupiter.api.Nested;
2224
import org.junit.jupiter.api.Test;
2325
import org.springframework.beans.factory.annotation.Autowired;
2426
import org.springframework.boot.test.mock.mockito.SpyBean;
@@ -30,9 +32,6 @@ class UnivApplyInfoQueryServiceTest {
3032
@Autowired
3133
private UnivApplyInfoQueryService univApplyInfoQueryService;
3234

33-
@SpyBean
34-
private UnivApplyInfoFilterRepository univApplyInfoFilterRepository;
35-
3635
@SpyBean
3736
private UnivApplyInfoRepository univApplyInfoRepository;
3837

@@ -42,164 +41,110 @@ class UnivApplyInfoQueryServiceTest {
4241
@Autowired
4342
private LanguageRequirementFixture languageRequirementFixture;
4443

45-
@Test
46-
void 대학_지원_정보를_상세_조회한다() {
47-
// given
48-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
49-
50-
// when
51-
UnivApplyInfoDetailResponse response = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
52-
53-
// then
54-
assertThat(response.id()).isEqualTo(괌대학_A_지원_정보.getId());
55-
}
56-
57-
@Test
58-
void 대학_지원_정보_상세_조회시_캐시가_적용된다() {
59-
// given
60-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
61-
62-
// when
63-
UnivApplyInfoDetailResponse firstResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
64-
UnivApplyInfoDetailResponse secondResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
65-
66-
// then
67-
assertThat(firstResponse).isEqualTo(secondResponse);
68-
then(univApplyInfoRepository).should(times(1)).getUnivApplyInfoById(괌대학_A_지원_정보.getId());
69-
}
70-
71-
@Test
72-
void 존재하지_않는_대학_지원_정보를_조회하면_예외가_발생한다() {
73-
// given
74-
Long invalidUnivApplyInfoId = 9999L;
75-
76-
// when & then
77-
assertThatExceptionOfType(RuntimeException.class)
78-
.isThrownBy(() -> univApplyInfoQueryService.getUnivApplyInfoDetail(invalidUnivApplyInfoId))
79-
.havingRootCause()
80-
.isInstanceOf(CustomException.class)
81-
.withMessage(UNIV_APPLY_INFO_NOT_FOUND.getMessage());
82-
}
83-
84-
@Test
85-
void 전체_대학_지원_정보를_조회한다() {
86-
// given
87-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
88-
UnivApplyInfo 괌대학_B_지원_정보 = univApplyInfoFixture.괌대학_B_지원_정보();
89-
UnivApplyInfo 네바다주립대학_라스베이거스_지원_정보 = univApplyInfoFixture.네바다주립대학_라스베이거스_지원_정보();
90-
UnivApplyInfo 서던덴마크대학교_지원_정보 = univApplyInfoFixture.서던덴마크대학교_지원_정보();
91-
UnivApplyInfo 그라츠대학_지원_정보 = univApplyInfoFixture.그라츠대학_지원_정보();
92-
UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture.메이지대학_지원_정보();
93-
94-
// when
95-
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfo(
96-
null, List.of(), null, null);
97-
98-
// then
99-
assertThat(response.univApplyInfoPreviews())
100-
.containsExactlyInAnyOrder(
101-
UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보),
102-
UnivApplyInfoPreviewResponse.from(괌대학_B_지원_정보),
103-
UnivApplyInfoPreviewResponse.from(네바다주립대학_라스베이거스_지원_정보),
104-
UnivApplyInfoPreviewResponse.from(서던덴마크대학교_지원_정보),
105-
UnivApplyInfoPreviewResponse.from(그라츠대학_지원_정보),
106-
UnivApplyInfoPreviewResponse.from(메이지대학_지원_정보)
107-
);
108-
}
109-
110-
@Test
111-
void 대학_지원_정보_조회시_캐시가_적용된다() {
112-
// given
113-
univApplyInfoFixture.괌대학_A_지원_정보();
114-
String regionCode = "AMERICAS";
115-
List<String> keywords = List.of("괌");
116-
LanguageTestType testType = LanguageTestType.TOEFL_IBT;
117-
String testScore = "70";
118-
String term = "2024-1";
119-
120-
// when
121-
UnivApplyInfoPreviewResponses firstResponse =
122-
univApplyInfoQueryService.searchUnivApplyInfo(regionCode, keywords, testType, testScore);
123-
UnivApplyInfoPreviewResponses secondResponse =
124-
univApplyInfoQueryService.searchUnivApplyInfo(regionCode, keywords, testType, testScore);
125-
126-
// then
127-
assertThat(firstResponse).isEqualTo(secondResponse);
128-
then(univApplyInfoFilterRepository).should(times(1))
129-
.findAllByRegionCodeAndKeywordsAndLanguageTestTypeAndTestScoreAndTerm(
130-
regionCode, keywords, testType, testScore, term);
131-
}
132-
133-
@Test
134-
void 지역으로_대학_지원_정보를_필터링한다() {
135-
// given
136-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
137-
univApplyInfoFixture.코펜하겐IT대학_지원_정보();
138-
univApplyInfoFixture.그라츠공과대학_지원_정보();
139-
univApplyInfoFixture.메이지대학_지원_정보();
140-
141-
// when
142-
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfo(
143-
"AMERICAS", List.of(), null, null);
144-
145-
// then
146-
assertThat(response.univApplyInfoPreviews())
147-
.containsExactlyInAnyOrder(UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보));
148-
}
149-
150-
@Test
151-
void 키워드로_대학_지원_정보를_필터링한다() {
152-
// given
153-
univApplyInfoFixture.괌대학_A_지원_정보();
154-
UnivApplyInfo 그라츠대학_지원_정보 = univApplyInfoFixture.그라츠대학_지원_정보();
155-
UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture.메이지대학_지원_정보();
156-
157-
// when
158-
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfo(
159-
null, List.of("라", "일본"), null, null);
160-
161-
// then
162-
assertThat(response.univApplyInfoPreviews())
163-
.containsExactlyInAnyOrder(
164-
UnivApplyInfoPreviewResponse.from(그라츠대학_지원_정보),
165-
UnivApplyInfoPreviewResponse.from(메이지대학_지원_정보)
166-
);
167-
}
168-
169-
@Test
170-
void 어학시험_조건으로_대학_지원_정보를_필터링한다() {
171-
// given
172-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
173-
languageRequirementFixture.토플_80(괌대학_A_지원_정보);
174-
languageRequirementFixture.토익_800(괌대학_A_지원_정보);
175-
UnivApplyInfo 괌대학_B_지원_정보 = univApplyInfoFixture.괌대학_B_지원_정보();
176-
languageRequirementFixture.토플_70(괌대학_B_지원_정보);
177-
languageRequirementFixture.토익_900(괌대학_B_지원_정보);
178-
179-
// when
180-
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfo(
181-
null, List.of(), LanguageTestType.TOEFL_IBT, "70");
182-
183-
// then
184-
assertThat(response.univApplyInfoPreviews())
185-
.containsExactlyInAnyOrder(UnivApplyInfoPreviewResponse.from(괌대학_B_지원_정보));
44+
@Nested
45+
class 대학_지원_정보_상세_조회 {
46+
47+
@Test
48+
void 대학_지원_정보를_상세_조회한다() {
49+
// given
50+
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
51+
52+
// when
53+
UnivApplyInfoDetailResponse response = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
54+
55+
// then
56+
assertThat(response.id()).isEqualTo(괌대학_A_지원_정보.getId());
57+
}
58+
59+
@Test
60+
void 대학_지원_정보_상세_조회시_캐시가_적용된다() {
61+
// given
62+
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
63+
64+
// when
65+
UnivApplyInfoDetailResponse firstResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
66+
UnivApplyInfoDetailResponse secondResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
67+
68+
// then
69+
assertThat(firstResponse).isEqualTo(secondResponse);
70+
then(univApplyInfoRepository).should(times(1)).getUnivApplyInfoById(괌대학_A_지원_정보.getId());
71+
}
72+
73+
@Test
74+
void 존재하지_않는_대학_지원_정보를_조회하면_예외가_발생한다() {
75+
// given
76+
Long invalidUnivApplyInfoId = 9999L;
77+
78+
// when & then
79+
assertThatExceptionOfType(RuntimeException.class)
80+
.isThrownBy(() -> univApplyInfoQueryService.getUnivApplyInfoDetail(invalidUnivApplyInfoId))
81+
.havingRootCause()
82+
.isInstanceOf(CustomException.class)
83+
.withMessage(UNIV_APPLY_INFO_NOT_FOUND.getMessage());
84+
}
18685
}
18786

188-
@Test
189-
void 모든_조건으로_대학_지원_정보를_필터링한다() {
190-
// given
191-
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
192-
languageRequirementFixture.토플_80(괌대학_A_지원_정보);
193-
languageRequirementFixture.토익_800(괌대학_A_지원_정보);
194-
UnivApplyInfo 서던덴마크대학교_지원_정보 = univApplyInfoFixture.서던덴마크대학교_지원_정보();
195-
languageRequirementFixture.토플_70(서던덴마크대학교_지원_정보);
196-
197-
// when
198-
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfo(
199-
"EUROPE", List.of(), LanguageTestType.TOEFL_IBT, "70");
200-
201-
// then
202-
assertThat(response.univApplyInfoPreviews())
203-
.containsExactly(UnivApplyInfoPreviewResponse.from(서던덴마크대학교_지원_정보));
87+
@Nested
88+
class 대학_지원_정보_필터링_검색 {
89+
90+
@Test
91+
void 어학_시험_종류로_필터링한다() {
92+
// given
93+
UnivApplyInfoFilterSearchRequest request = new UnivApplyInfoFilterSearchRequest(TOEIC, null, null);
94+
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
95+
languageRequirementFixture.토익_800(괌대학_A_지원_정보);
96+
UnivApplyInfo 괌대학_B_지원_정보 = univApplyInfoFixture.괌대학_B_지원_정보();
97+
languageRequirementFixture.토플_70(괌대학_B_지원_정보);
98+
99+
// when
100+
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByFilter(request);
101+
102+
// then
103+
assertThat(response.univApplyInfoPreviews())
104+
.containsExactly(UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보));
105+
}
106+
107+
@Test
108+
void 어학_시험_점수가_기준치_이상인_곳을_필터링한다() {
109+
// given
110+
UnivApplyInfoFilterSearchRequest request = new UnivApplyInfoFilterSearchRequest(TOEIC, "800", null);
111+
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
112+
languageRequirementFixture.토익_800(괌대학_A_지원_정보);
113+
UnivApplyInfo 괌대학_B_지원_정보 = univApplyInfoFixture.괌대학_B_지원_정보();
114+
languageRequirementFixture.토익_900(괌대학_B_지원_정보);
115+
116+
// when
117+
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByFilter(request);
118+
119+
// then
120+
assertThat(response.univApplyInfoPreviews())
121+
.containsExactlyInAnyOrder(UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보));
122+
}
123+
124+
@Test
125+
void 국가_코드로_필터링한다() {
126+
// given
127+
UnivApplyInfoFilterSearchRequest request1 = new UnivApplyInfoFilterSearchRequest(TOEIC, null, List.of("US"));
128+
UnivApplyInfoFilterSearchRequest request2 = new UnivApplyInfoFilterSearchRequest(TOEIC, null, List.of("US", "CA"));
129+
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보();
130+
languageRequirementFixture.토익_800(괌대학_A_지원_정보);
131+
UnivApplyInfo 메모리얼대학_세인트존스_A_지원_정보 = univApplyInfoFixture.메모리얼대학_세인트존스_A_지원_정보();
132+
languageRequirementFixture.토익_800(메모리얼대학_세인트존스_A_지원_정보);
133+
134+
// when
135+
UnivApplyInfoPreviewResponses response1 = univApplyInfoQueryService.searchUnivApplyInfoByFilter(request1);
136+
UnivApplyInfoPreviewResponses response2 = univApplyInfoQueryService.searchUnivApplyInfoByFilter(request2);
137+
138+
// then
139+
assertAll(
140+
() -> assertThat(response1.univApplyInfoPreviews())
141+
.containsExactly(UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보)),
142+
() -> assertThat(response2.univApplyInfoPreviews())
143+
.containsExactlyInAnyOrder(
144+
UnivApplyInfoPreviewResponse.from(괌대학_A_지원_정보),
145+
UnivApplyInfoPreviewResponse.from(메모리얼대학_세인트존스_A_지원_정보)
146+
)
147+
);
148+
}
204149
}
205150
}

0 commit comments

Comments
 (0)