1
+ package com .moplus .moplus_server .statistic .Problem .service ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+ import static org .mockito .BDDMockito .given ;
5
+ import static org .mockito .Mockito .verify ;
6
+
7
+ import com .moplus .moplus_server .statistic .Problem .domain .ChildProblemStatistic ;
8
+ import com .moplus .moplus_server .statistic .Problem .domain .ProblemSetStatistic ;
9
+ import com .moplus .moplus_server .statistic .Problem .domain .ProblemStatistic ;
10
+ import com .moplus .moplus_server .statistic .Problem .domain .StatisticEntityTarget ;
11
+ import com .moplus .moplus_server .statistic .Problem .domain .StatisticFieldType ;
12
+ import com .moplus .moplus_server .statistic .Problem .repository .ChildProblemStatisticRepository ;
13
+ import com .moplus .moplus_server .statistic .Problem .repository .ProblemSetStatisticRepository ;
14
+ import com .moplus .moplus_server .statistic .Problem .repository .ProblemStatisticRepository ;
15
+ import org .junit .jupiter .api .Test ;
16
+ import org .junit .jupiter .api .extension .ExtendWith ;
17
+ import org .mockito .InjectMocks ;
18
+ import org .mockito .Mock ;
19
+ import org .mockito .junit .jupiter .MockitoExtension ;
20
+
21
+ @ ExtendWith (MockitoExtension .class )
22
+ class CountStatisticsUpdateServiceTest {
23
+
24
+ @ InjectMocks
25
+ private CountStatisticsUpdateService countStatisticsUpdateService ;
26
+
27
+ @ Mock
28
+ private ProblemStatisticRepository problemStatisticRepository ;
29
+ @ Mock
30
+ private ProblemSetStatisticRepository problemSetStatisticRepository ;
31
+ @ Mock
32
+ private ChildProblemStatisticRepository childProblemStatisticRepository ;
33
+
34
+ @ Test
35
+ void 문항_조회수_증가 () {
36
+ // given
37
+ Long problemId = 1L ;
38
+ ProblemStatistic problemStatistic = new ProblemStatistic (problemId );
39
+ given (problemStatisticRepository .findByIdElseThrow (problemId ))
40
+ .willReturn (problemStatistic );
41
+
42
+ // when
43
+ countStatisticsUpdateService .updateStatistics (problemId , StatisticFieldType .VIEW ,
44
+ StatisticEntityTarget .PROBLEM );
45
+
46
+ // then
47
+ verify (problemStatisticRepository ).findByIdElseThrow (problemId );
48
+ assertThat (problemStatistic .getViewCount ()).isEqualTo (1L );
49
+ assertThat (problemStatistic .getSubmitCount ()).isEqualTo (0L );
50
+ }
51
+
52
+ @ Test
53
+ void 문항세트_풀이수_증가 () {
54
+ // given
55
+ Long problemSetId = 1L ;
56
+ ProblemSetStatistic problemSetStatistic = new ProblemSetStatistic (problemSetId );
57
+ given (problemSetStatisticRepository .findByIdElseThrow (problemSetId ))
58
+ .willReturn (problemSetStatistic );
59
+
60
+ // when
61
+ countStatisticsUpdateService .updateStatistics (problemSetId , StatisticFieldType .SUBMIT ,
62
+ StatisticEntityTarget .PROBLEM_SET );
63
+
64
+ // then
65
+ verify (problemSetStatisticRepository ).findByIdElseThrow (problemSetId );
66
+ assertThat (problemSetStatistic .getSubmitCount ()).isEqualTo (1L );
67
+ assertThat (problemSetStatistic .getViewCount ()).isEqualTo (0L );
68
+ }
69
+
70
+ @ Test
71
+ void 새끼문항_조회수_증가 () {
72
+ // given
73
+ Long childProblemId = 1L ;
74
+ ChildProblemStatistic childProblemStatistic = new ChildProblemStatistic (childProblemId );
75
+ given (childProblemStatisticRepository .findByIdElseThrow (childProblemId ))
76
+ .willReturn (childProblemStatistic );
77
+
78
+ // when
79
+ countStatisticsUpdateService .updateStatistics (childProblemId , StatisticFieldType .VIEW ,
80
+ StatisticEntityTarget .CHILD_PROBLEM );
81
+
82
+ // then
83
+ verify (childProblemStatisticRepository ).findByIdElseThrow (childProblemId );
84
+ assertThat (childProblemStatistic .getViewCount ()).isEqualTo (1L );
85
+ assertThat (childProblemStatistic .getSubmitCount ()).isEqualTo (0L );
86
+ }
87
+ }
0 commit comments