66import org .junit .jupiter .api .Test ;
77
88import com .loopers .batch .job .ranking .support .ScoreCalculator ;
9+ import com .loopers .domain .metrics .ProductMetricsAggregation ;
910
1011@ DisplayName ("RankingAggregation 단위 테스트" )
1112class RankingAggregationUnitTest {
@@ -20,10 +21,12 @@ class 집계_결과로부터_생성 {
2021 @ DisplayName ("유효한 집계 결과로부터 객체를 생성한다" )
2122 void should_create_from_valid_aggregation_result () {
2223 // given
23- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )}; // productId, view, like, sales, order, amount
24+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
25+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
26+ );
2427
2528 // when
26- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
29+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
2730
2831 // then
2932 Assertions .assertThat (aggregation .getProductId ()).isEqualTo (1L );
@@ -38,52 +41,12 @@ void should_create_from_valid_aggregation_result() {
3841 }
3942
4043 @ Test
41- @ DisplayName ("null 배열에 대해 예외가 발생한다" )
42- void should_throw_exception_when_row_is_null () {
44+ @ DisplayName ("null 메트릭에 대해 예외가 발생한다" )
45+ void should_throw_exception_when_metrics_is_null () {
4346 // given & when & then
4447 Assertions .assertThatThrownBy (() -> RankingAggregation .from (null , calculator ))
4548 .isInstanceOf (IllegalArgumentException .class )
46- .hasMessageContaining ("집계 결과 배열이 null이거나 길이가 부족합니다" );
47- }
48-
49- @ Test
50- @ DisplayName ("길이가 부족한 배열에 대해 예외가 발생한다" )
51- void should_throw_exception_when_row_length_is_insufficient () {
52- // given
53- Object [] shortRow = {1L , 100L , 50L }; // 길이 3 (6 미만)
54-
55- // when & then
56- Assertions .assertThatThrownBy (() -> RankingAggregation .from (shortRow , calculator ))
57- .isInstanceOf (IllegalArgumentException .class )
58- .hasMessageContaining ("집계 결과 배열이 null이거나 길이가 부족합니다" );
59- }
60-
61- @ Test
62- @ DisplayName ("잘못된 데이터 타입에 대해 예외가 발생한다" )
63- void should_throw_exception_when_data_type_is_invalid () {
64- // given
65- Object [] invalidRow = {"invalid" , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )}; // productId가 String
66-
67- // when & then
68- Assertions .assertThatThrownBy (() -> RankingAggregation .from (invalidRow , calculator ))
69- .isInstanceOf (IllegalArgumentException .class )
70- .hasMessageContaining ("집계 결과 데이터 형식이 올바르지 않습니다" );
71- }
72-
73- @ Test
74- @ DisplayName ("Number 타입의 다양한 형태를 처리한다" )
75- void should_handle_various_number_types () {
76- // given - Integer, Long, BigDecimal 등 다양한 Number 타입
77- Object [] row = {1L , 100 , 50L , 10 , 5L , java .math .BigDecimal .valueOf (1000 )};
78-
79- // when
80- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
81-
82- // then
83- Assertions .assertThat (aggregation .getViewCount ()).isEqualTo (100L );
84- Assertions .assertThat (aggregation .getLikeCount ()).isEqualTo (50L );
85- Assertions .assertThat (aggregation .getSalesCount ()).isEqualTo (10L );
86- Assertions .assertThat (aggregation .getOrderCount ()).isEqualTo (5L );
49+ .hasMessageContaining ("집계 결과(metrics)가 null입니다." );
8750 }
8851 }
8952
@@ -95,8 +58,10 @@ class 순위_부여 {
9558 @ DisplayName ("유효한 순위를 부여한다" )
9659 void should_assign_valid_rank () {
9760 // given
98- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )};
99- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
61+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
62+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
63+ );
64+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
10065
10166 // when
10267 aggregation .assignRank (1 );
@@ -109,8 +74,10 @@ void should_assign_valid_rank() {
10974 @ DisplayName ("100위까지 순위를 부여할 수 있다" )
11075 void should_assign_rank_up_to_100 () {
11176 // given
112- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )};
113- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
77+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
78+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
79+ );
80+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
11481
11582 // when
11683 aggregation .assignRank (100 );
@@ -123,8 +90,10 @@ void should_assign_rank_up_to_100() {
12390 @ DisplayName ("0 이하의 순위에 대해 예외가 발생한다" )
12491 void should_throw_exception_when_rank_is_zero_or_negative () {
12592 // given
126- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )};
127- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
93+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
94+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
95+ );
96+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
12897
12998 // when & then
13099 Assertions .assertThatThrownBy (() -> aggregation .assignRank (0 ))
@@ -140,8 +109,10 @@ void should_throw_exception_when_rank_is_zero_or_negative() {
140109 @ DisplayName ("100을 초과하는 순위에 대해 예외가 발생한다" )
141110 void should_throw_exception_when_rank_exceeds_100 () {
142111 // given
143- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )};
144- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
112+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
113+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
114+ );
115+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
145116
146117 // when & then
147118 Assertions .assertThatThrownBy (() -> aggregation .assignRank (101 ))
@@ -158,8 +129,10 @@ class 문자열_표현 {
158129 @ DisplayName ("toString이 올바른 형식을 반환한다" )
159130 void should_return_correct_string_format () {
160131 // given
161- Object [] row = {1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )};
162- RankingAggregation aggregation = RankingAggregation .from (row , calculator );
132+ ProductMetricsAggregation metrics = new ProductMetricsAggregation (
133+ 1L , 100L , 50L , 10L , 5L , java .math .BigDecimal .valueOf (1000 )
134+ );
135+ RankingAggregation aggregation = RankingAggregation .from (metrics , calculator );
163136 aggregation .assignRank (1 );
164137
165138 // when
0 commit comments