Skip to content

Commit b0879ef

Browse files
committed
test: service들 패키지 위치, 이름 변경, 커맨드 도입 등으로 인한 관련 테스트 코드 수정
1 parent 12f6df9 commit b0879ef

11 files changed

Lines changed: 359 additions & 306 deletions

File tree

module-api/src/test/java/com/mycodingtest/api/collector/BojCollectorQueryControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.mycodingtest.api.collector;
22

3-
import com.mycodingtest.application.collector.BojIngestionService;
3+
import com.mycodingtest.application.collector.command.BojIngestionCommandService;
44
import org.junit.jupiter.api.Nested;
55
import org.junit.jupiter.api.Test;
66
import org.junit.jupiter.api.extension.ExtendWith;
@@ -18,7 +18,7 @@
1818
class BojCollectorQueryControllerTest {
1919

2020
@Mock
21-
private BojIngestionService bojIngestionService;
21+
private BojIngestionCommandService bojIngestionCommandService;
2222

2323
@InjectMocks
2424
private BojCollectorQueryController controller;
@@ -30,7 +30,7 @@ class 중복_제출_확인 {
3030
void 중복이_아니면_OK를_반환한다() {
3131
// given
3232
Long submissionId = 12345L;
33-
willDoNothing().given(bojIngestionService).checkDuplicatedSubmissionId(submissionId);
33+
willDoNothing().given(bojIngestionCommandService).checkDuplicatedSubmissionId(submissionId);
3434

3535
// when
3636
ResponseEntity<Void> result = controller.getDuplicatedSubmissionIdCheckResult(submissionId);
@@ -44,7 +44,7 @@ class 중복_제출_확인 {
4444
// given
4545
Long submissionId = 99999L;
4646
willThrow(new IllegalStateException("이미 존재하는 제출 번호입니다"))
47-
.given(bojIngestionService).checkDuplicatedSubmissionId(submissionId);
47+
.given(bojIngestionCommandService).checkDuplicatedSubmissionId(submissionId);
4848

4949
// when
5050
ResponseEntity<Void> result = controller.getDuplicatedSubmissionIdCheckResult(submissionId);

module-api/src/test/java/com/mycodingtest/api/judgment/JudgmentQueryControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.mycodingtest.api.judgment;
22

3-
import com.mycodingtest.application.judgment.JudgmentService;
3+
import com.mycodingtest.application.judgment.command.JudgmentCommandService;
44
import com.mycodingtest.domain.common.Platform;
55
import com.mycodingtest.domain.judgment.Judgment;
66
import com.mycodingtest.domain.judgment.JudgmentStatus;
@@ -22,7 +22,7 @@
2222
class JudgmentQueryControllerTest {
2323

2424
@Mock
25-
private JudgmentService judgmentService;
25+
private JudgmentCommandService judgmentCommandService;
2626

2727
@InjectMocks
2828
private JudgmentQueryController judgmentQueryController;
@@ -40,7 +40,7 @@ class 채점_결과_목록_조회 {
4040
List<Judgment> judgments = List.of(
4141
Judgment.from( problemId, userId, 12345L, JudgmentStatus.SUCCESS, Platform.BOJ, null, "code1"),
4242
Judgment.from( problemId, userId, 12346L, JudgmentStatus.FAIL, Platform.BOJ, null, "code2"));
43-
given(judgmentService.getJudgments(problemId, userId)).willReturn(judgments);
43+
given(judgmentCommandService.getJudgments(problemId, userId)).willReturn(judgments);
4444

4545
// when
4646
var result = judgmentQueryController.getJudgmentResultList(problemId, userDetails);
@@ -58,7 +58,7 @@ class 채점_결과_목록_조회 {
5858
Long problemId = 9999L;
5959
Long userId = 1L;
6060
CustomUserDetails userDetails = new CustomUserDetails(userId, "pic", "user");
61-
given(judgmentService.getJudgments(problemId, userId)).willReturn(List.of());
61+
given(judgmentCommandService.getJudgments(problemId, userId)).willReturn(List.of());
6262

6363
// when
6464
var result = judgmentQueryController.getJudgmentResultList(problemId, userDetails);

module-api/src/test/java/com/mycodingtest/api/review/ReviewCommandControllerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.mycodingtest.api.review;
22

33
import com.mycodingtest.api.review.dto.request.UpdateReviewRequest;
4-
import com.mycodingtest.application.review.ReviewService;
4+
import com.mycodingtest.application.review.command.ReviewCommandService;
5+
import com.mycodingtest.application.review.command.UpdateReviewResult;
56
import com.mycodingtest.domain.review.Review;
67
import com.mycodingtest.domain.review.ReviewStatus;
78
import com.mycodingtest.security.CustomUserDetails;
@@ -15,14 +16,13 @@
1516

1617
import static org.assertj.core.api.Assertions.assertThat;
1718
import static org.mockito.ArgumentMatchers.any;
18-
import static org.mockito.ArgumentMatchers.nullable;
1919
import static org.mockito.BDDMockito.given;
2020

2121
@ExtendWith(MockitoExtension.class)
2222
class ReviewCommandControllerTest {
2323

2424
@Mock
25-
private ReviewService reviewService;
25+
private ReviewCommandService reviewCommandService;
2626

2727
@InjectMocks
2828
private ReviewCommandController controller;
@@ -59,7 +59,7 @@ class 리뷰_수정 {
5959
true,
6060
null,
6161
null);
62-
given(reviewService.updateReview(any())).willReturn(updatedReview);
62+
given(reviewCommandService.updateReview(any())).willReturn(UpdateReviewResult.from(updatedReview));
6363

6464
// when
6565
var result = controller.updateReview(reviewId, request, userDetails);
@@ -99,7 +99,7 @@ class 리뷰_수정 {
9999
true,
100100
null,
101101
null);
102-
given(reviewService.updateReview(any())).willReturn(updatedReview);
102+
given(reviewCommandService.updateReview(any())).willReturn(UpdateReviewResult.from(updatedReview));
103103

104104
// when
105105
var result = controller.updateReview(reviewId, request, userDetails);

module-api/src/test/java/com/mycodingtest/api/review/ReviewQueryControllerTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.mycodingtest.api.review;
22

3-
import com.mycodingtest.application.review.ReviewService;
4-
import com.mycodingtest.application.review.dto.PagedResult;
5-
import com.mycodingtest.application.review.dto.ReviewSummary;
3+
import com.mycodingtest.application.review.command.ReviewCommandService;
4+
import com.mycodingtest.application.review.query.ReviewSummaryPage;
5+
import com.mycodingtest.application.review.query.ReviewSummary;
66
import com.mycodingtest.domain.review.Review;
77
import com.mycodingtest.domain.review.ReviewStatus;
88
import com.mycodingtest.security.CustomUserDetails;
@@ -23,7 +23,7 @@
2323
class ReviewQueryControllerTest {
2424

2525
@Mock
26-
private ReviewService reviewService;
26+
private ReviewCommandService reviewCommandService;
2727

2828
@InjectMocks
2929
private ReviewQueryController controller;
@@ -52,7 +52,7 @@ class 리뷰_단건_조회 {
5252
true,
5353
null,
5454
null);
55-
given(reviewService.getReview(reviewId, userId)).willReturn(review);
55+
given(reviewCommandService.getReview(reviewId, userId)).willReturn(review);
5656

5757
// when
5858
var result = controller.getReview(reviewId, userDetails);
@@ -73,7 +73,7 @@ class 대기중_리뷰_개수_조회 {
7373
// given
7474
Long userId = 1L;
7575
CustomUserDetails userDetails = new CustomUserDetails(userId, "pic", "user");
76-
given(reviewService.getReviewCountStatusInToDo(userId)).willReturn(5L);
76+
given(reviewCommandService.getReviewCountStatusInToDo(userId)).willReturn(5L);
7777

7878
// when
7979
var result = controller.getWaitReviewCount(userDetails);
@@ -97,14 +97,14 @@ class 리뷰_목록_페이징_조회 {
9797
int size = 10;
9898
ReviewStatus filter = ReviewStatus.TO_DO;
9999

100-
PagedResult<ReviewSummary> pagedResult = new PagedResult<>(
100+
ReviewSummaryPage<ReviewSummary> reviewSummaryPage = new ReviewSummaryPage<>(
101101
List.of(),
102102
0,
103103
0,
104104
0,
105105
10,
106106
true);
107-
given(reviewService.getReviewSummaries(userId, page, size, filter)).willReturn(pagedResult);
107+
given(reviewCommandService.getReviewSummaries(userId, page, size, filter)).willReturn(reviewSummaryPage);
108108

109109
// when
110110
var result = controller.getReviewSummaries(userDetails, page, size, filter);

module-application/src/test/java/com/mycodingtest/application/collector/BojIngestionServiceTest.java renamed to module-application/src/test/java/com/mycodingtest/application/collector/BojIngestionCommandServiceTest.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.mycodingtest.application.collector;
22

3-
import com.mycodingtest.application.collector.dto.CreateProblemAndJudgmentCommand;
4-
import com.mycodingtest.application.judgment.JudgmentService;
5-
import com.mycodingtest.application.problem.ProblemService;
6-
import com.mycodingtest.application.review.ReviewService;
3+
import com.mycodingtest.application.collector.command.BojIngestionCommandService;
4+
import com.mycodingtest.application.collector.command.CreateProblemAndJudgmentCommand;
5+
import com.mycodingtest.application.judgment.command.JudgmentCommandService;
6+
import com.mycodingtest.application.judgment.query.JudgmentQueryService;
7+
import com.mycodingtest.application.problem.command.ProblemCommandService;
8+
import com.mycodingtest.application.review.command.ReviewCommandService;
79
import com.mycodingtest.domain.common.Platform;
810
import com.mycodingtest.domain.problem.Problem;
911
import org.junit.jupiter.api.Nested;
@@ -21,19 +23,21 @@
2123
import static org.mockito.Mockito.verify;
2224

2325
@ExtendWith(MockitoExtension.class)
24-
class BojIngestionServiceTest {
26+
class BojIngestionCommandServiceTest {
2527

2628
@Mock
27-
private JudgmentService judgmentService;
29+
private JudgmentCommandService judgmentCommandService;
30+
@Mock
31+
private JudgmentQueryService judgmentQueryService;
2832

2933
@Mock
30-
private ProblemService problemService;
34+
private ProblemCommandService problemCommandService;
3135

3236
@Mock
33-
private ReviewService reviewService;
37+
private ReviewCommandService reviewCommandService;
3438

3539
@InjectMocks
36-
private BojIngestionService bojIngestionService;
40+
private BojIngestionCommandService bojIngestionCommandService;
3741

3842
@Nested
3943
class 데이터_수집 {
@@ -56,17 +60,15 @@ class 데이터_수집 {
5660
.sourceCode("public class Main {}")
5761
.build();
5862

59-
Problem mockProblem = Problem.from(1000, "A+B", Platform.BOJ);
60-
61-
given(problemService.getOrCreateProblem(any())).willReturn(mockProblem);
63+
given(problemCommandService.syncProblem(any()));
6264

6365
// when
64-
bojIngestionService.ingest(command);
66+
bojIngestionCommandService.ingest(command);
6567

6668
// then
67-
verify(problemService).getOrCreateProblem(any());
68-
verify(judgmentService).createJudgmentFromBoj(any());
69-
verify(reviewService).createReview(any());
69+
verify(problemCommandService).syncProblem(any());
70+
verify(judgmentCommandService).createJudgmentFromBoj(any());
71+
verify(reviewCommandService).createReview(any());
7072
}
7173
}
7274

@@ -77,10 +79,10 @@ class 중복_제출_확인 {
7779
void 중복_제출이면_예외가_발생한다() {
7880
// given
7981
Long submissionId = 99999L;
80-
given(judgmentService.isJudgmentExist(submissionId, Platform.BOJ)).willReturn(true);
82+
given(judgmentQueryService.isJudgmentExist(submissionId, Platform.BOJ)).willReturn(true);
8183

8284
// when & then
83-
assertThatThrownBy(() -> bojIngestionService.checkDuplicatedSubmissionId(submissionId))
85+
assertThatThrownBy(() -> bojIngestionCommandService.checkDuplicatedSubmissionId(submissionId))
8486
.isInstanceOf(IllegalStateException.class)
8587
.hasMessageContaining("이미 존재하는 제출 번호입니다");
8688
}
@@ -89,10 +91,10 @@ class 중복_제출_확인 {
8991
void 중복이_아니면_예외가_발생하지_않는다() {
9092
// given
9193
Long submissionId = 99999L;
92-
given(judgmentService.isJudgmentExist(submissionId, Platform.BOJ)).willReturn(false);
94+
given(judgmentQueryService.isJudgmentExist(submissionId, Platform.BOJ)).willReturn(false);
9395

9496
// when & then
95-
bojIngestionService.checkDuplicatedSubmissionId(submissionId);
97+
bojIngestionCommandService.checkDuplicatedSubmissionId(submissionId);
9698
// 예외가 발생하지 않으면 성공
9799
}
98100
}

0 commit comments

Comments
 (0)