11package org .myteam .server .notice .service ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .junit .Assert .assertThrows ;
5+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
6+ import static org .mockito .Mockito .verify ;
7+ import static org .mockito .Mockito .when ;
8+
9+ import java .util .ArrayList ;
10+ import java .util .List ;
311import org .junit .jupiter .api .BeforeEach ;
412import org .junit .jupiter .api .DisplayName ;
513import org .junit .jupiter .api .Test ;
6- import org .myteam .server .support .IntegrationTestSupport ;
714import org .myteam .server .global .exception .ErrorCode ;
815import org .myteam .server .global .exception .PlayHiveException ;
916import org .myteam .server .member .entity .Member ;
1017import org .myteam .server .notice .domain .Notice ;
1118import org .myteam .server .report .domain .DomainType ;
19+ import org .myteam .server .support .IntegrationTestSupport ;
1220import org .springframework .beans .factory .annotation .Autowired ;
1321import org .springframework .transaction .annotation .Transactional ;
1422
15- import static org .assertj .core .api .Assertions .assertThat ;
16- import static org .junit .Assert .assertEquals ;
17- import static org .junit .Assert .assertThrows ;
18- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
19- import static org .mockito .Mockito .verify ;
20- import static org .mockito .Mockito .when ;
21-
2223class NoticeDeleteServiceTest extends IntegrationTestSupport {
2324
2425 @ Autowired
@@ -27,7 +28,9 @@ class NoticeDeleteServiceTest extends IntegrationTestSupport {
2728 private Member author ;
2829 private Member other ;
2930 private Member admin ;
30- private Notice notice ;
31+ private Notice notice1 ;
32+ private Notice notice2 ;
33+ List <Long > noticeIdList = new ArrayList <>();
3134
3235 @ BeforeEach
3336 void setUp () {
@@ -41,35 +44,44 @@ void setUp() {
4144 @ DisplayName ("케이스 1: 작성자가 삭제 요청 → 성공" )
4245 void deleteNotice_by_author_success () {
4346 // given
44- notice = createNotice (admin , "Original Title" , "Original Content" , null );
47+ notice1 = createNotice (admin , "Original Title" , "Original Content" , null );
48+ notice2 = createNotice (admin , "Original Title" , "Original Content" , null );
49+
50+ noticeIdList .add (notice1 .getId ());
51+ noticeIdList .add (notice2 .getId ());
52+
4553 when (securityReadService .getMember ()).thenReturn (admin );
4654
4755 // when && then
48- assertDoesNotThrow (() -> noticeService .deleteNotice (notice . getId () ));
56+ assertDoesNotThrow (() -> noticeService .deleteNotice (noticeIdList ));
4957 }
5058
5159 @ Transactional
5260 @ Test
5361 @ DisplayName ("케이스 2: 관리자가 삭제 요청 → 성공" )
5462 void deleteNotice_by_admin_success () {
5563 // given
56- notice = createNotice (admin , "Original Title" , "Original Content" , null );
64+ notice1 = createNotice (admin , "Original Title" , "Original Content" , null );
65+ noticeIdList .add (notice1 .getId ());
66+
5767 when (securityReadService .getMember ()).thenReturn (admin );
5868
5969 // when && then
60- assertDoesNotThrow (() -> noticeService .deleteNotice (notice . getId () ));
70+ assertDoesNotThrow (() -> noticeService .deleteNotice (noticeIdList ));
6171 }
6272
6373 @ Test
6474 @ DisplayName ("케이스 3: 작성자도 관리자도 아닌 유저가 삭제 요청 → 예외 발생" )
6575 void deleteNotice_by_outsider_throws () {
6676 // given
67- notice = createNotice (admin , "Original Title" , "Original Content" , null );
77+ notice1 = createNotice (admin , "Original Title" , "Original Content" , null );
78+ noticeIdList .add (notice1 .getId ());
79+
6880 when (securityReadService .getMember ()).thenReturn (other );
6981
7082 // when
7183 PlayHiveException ex = assertThrows (PlayHiveException .class , () ->
72- noticeService .deleteNotice (notice . getId () ));
84+ noticeService .deleteNotice (noticeIdList ));
7385
7486 // then
7587 assertThat (ex .getErrorCode ()).isEqualTo (ErrorCode .UNAUTHORIZED );
@@ -80,40 +92,51 @@ void deleteNotice_by_outsider_throws() {
8092 @ DisplayName ("케이스 4: 작성자가 삭제 요청 → 성공 + 이미지 삭제 호출" )
8193 void deleteNotice_by_author_success_img () {
8294 // given
83- notice = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
95+ notice1 = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
96+
97+ noticeIdList .add (notice1 .getId ());
98+
8499 when (securityReadService .getMember ()).thenReturn (admin );
85100
86101 // when
87- assertDoesNotThrow (() -> noticeService .deleteNotice (notice . getId () ));
102+ assertDoesNotThrow (() -> noticeService .deleteNotice (noticeIdList ));
88103
89104 // then
90- verify (s3Service ).deleteFile (notice .getImgUrl ()); // 이미지 삭제 확인
91- verify (redisCountService ).removeCount (DomainType .NOTICE , notice .getId ()); // Redis 카운트 삭제
105+ verify (s3Service ).deleteFile (notice1 .getImgUrl ()); // 이미지 삭제 확인
106+ verify (redisCountService ).removeCount (DomainType .NOTICE , notice1 .getId ()); // Redis 카운트 삭제
92107 }
93108
94109 @ Transactional
95110 @ Test
96111 @ DisplayName ("케이스 5: 관리자가 삭제 요청 → 성공" )
97112 void deleteNotice_by_admin_success_img () {
98113 // given
99- notice = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
114+ notice1 = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
115+
116+ noticeIdList .add (notice1 .getId ());
117+
100118 when (securityReadService .getMember ()).thenReturn (admin );
101119
102120 // when && then
103- assertDoesNotThrow (() -> noticeService .deleteNotice (notice .getId ()));
121+ assertDoesNotThrow (() -> noticeService .deleteNotice (noticeIdList ));
122+ verify (s3Service ).deleteFile (notice1 .getImgUrl ()); // 이미지 삭제 확인
123+ verify (redisCountService ).removeCount (DomainType .NOTICE , notice1 .getId ()); // Redis 카운트 삭제
104124 }
105125
106126 @ Transactional
107127 @ Test
108128 @ DisplayName ("케이스 6: 작성자도 관리자도 아닌 유저가 삭제 요청 → 예외 발생" )
109129 void deleteNotice_by_outsider_throws_img () {
110130 // given
111- notice = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
131+ notice1 = createNotice (admin , "Original Title" , "Original Content" , "test.co.kr" );
132+
133+ noticeIdList .add (notice1 .getId ());
134+
112135 when (securityReadService .getMember ()).thenReturn (other );
113136
114137 // when
115138 PlayHiveException ex = assertThrows (PlayHiveException .class , () ->
116- noticeService .deleteNotice (notice . getId () ));
139+ noticeService .deleteNotice (noticeIdList ));
117140
118141 // then
119142 assertThat (ex .getErrorCode ()).isEqualTo (ErrorCode .UNAUTHORIZED );
0 commit comments