Skip to content

Commit 4d18f75

Browse files
committed
Test: 기존 테스트 코드 수정
1 parent b545f5f commit 4d18f75

File tree

5 files changed

+139
-65
lines changed

5 files changed

+139
-65
lines changed

src/test/java/com/back/domain/notification/controller/NotificationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void t1() throws Exception {
118118

119119
given(userRepository.findById(1L)).willReturn(Optional.of(receiver));
120120
given(userRepository.findById(2L)).willReturn(Optional.of(actor));
121-
given(notificationService.createPersonalNotification(any(), any(), any(), any(), any()))
121+
given(notificationService.createPersonalNotification(any(), any(), any(), any(), any(), any()))
122122
.willReturn(notification);
123123

124124
// when

src/test/java/com/back/domain/notification/event/community/CommunityNotificationEventListenerTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.back.domain.notification.event.community;
22

3+
import com.back.domain.notification.entity.NotificationSettingType;
34
import com.back.domain.notification.service.NotificationService;
45
import com.back.domain.user.entity.User;
56
import com.back.domain.user.repository.UserRepository;
@@ -74,7 +75,8 @@ void t1() {
7475
eq(actor),
7576
anyString(), // title
7677
anyString(), // content
77-
eq("/posts/100")
78+
eq("/posts/100"),
79+
eq(NotificationSettingType.POST_COMMENT)
7880
);
7981
}
8082

@@ -97,7 +99,7 @@ void t2() {
9799

98100
// then
99101
verify(notificationService, never()).createCommunityNotification(
100-
any(), any(), anyString(), anyString(), anyString()
102+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
101103
);
102104
}
103105

@@ -121,7 +123,7 @@ void t3() {
121123

122124
// then
123125
verify(notificationService, never()).createCommunityNotification(
124-
any(), any(), anyString(), anyString(), anyString()
126+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
125127
);
126128
}
127129

@@ -152,7 +154,8 @@ void t4() {
152154
eq(actor),
153155
anyString(),
154156
anyString(),
155-
eq("/posts/100#comment-200")
157+
eq("/posts/100#comment-200"),
158+
eq(NotificationSettingType.POST_COMMENT)
156159
);
157160
}
158161

@@ -176,7 +179,7 @@ void t5() {
176179

177180
// then
178181
verify(notificationService, never()).createCommunityNotification(
179-
any(), any(), anyString(), anyString(), anyString()
182+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
180183
);
181184
}
182185

@@ -205,7 +208,8 @@ void t6() {
205208
eq(actor),
206209
anyString(),
207210
anyString(),
208-
eq("/posts/100")
211+
eq("/posts/100"),
212+
eq(NotificationSettingType.POST_LIKE)
209213
);
210214
}
211215

@@ -228,7 +232,7 @@ void t7() {
228232

229233
// then
230234
verify(notificationService, never()).createCommunityNotification(
231-
any(), any(), anyString(), anyString(), anyString()
235+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
232236
);
233237
}
234238

@@ -258,7 +262,8 @@ void t8() {
258262
eq(actor),
259263
anyString(),
260264
anyString(),
261-
eq("/posts/100#comment-200")
265+
eq("/posts/100#comment-200"),
266+
eq(NotificationSettingType.POST_LIKE)
262267
);
263268
}
264269

@@ -286,7 +291,8 @@ void t9() {
286291
eq(actor), // actor
287292
anyString(),
288293
anyString(),
289-
anyString()
294+
anyString(),
295+
eq(NotificationSettingType.POST_LIKE)
290296
);
291297
}
292298

@@ -305,15 +311,15 @@ void t10() {
305311

306312
willThrow(new RuntimeException("알림 생성 실패"))
307313
.given(notificationService).createCommunityNotification(
308-
any(), any(), anyString(), anyString(), anyString()
314+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
309315
);
310316

311317
// when & then - 예외가 전파되지 않아야 함
312318
assertThatCode(() -> listener.handleCommentCreated(event))
313319
.doesNotThrowAnyException();
314320

315321
verify(notificationService).createCommunityNotification(
316-
any(), any(), anyString(), anyString(), anyString()
322+
any(), any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
317323
);
318324
}
319325
}

src/test/java/com/back/domain/notification/event/study/StudyNotificationEventListenerTest.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.back.domain.notification.event.study;
22

3+
import com.back.domain.notification.entity.NotificationSettingType;
34
import com.back.domain.notification.service.NotificationService;
45
import com.back.domain.user.entity.User;
56
import com.back.domain.user.repository.UserRepository;
@@ -61,12 +62,12 @@ void t1() {
6162
listener.handleStudyRecordCreated(event);
6263

6364
// then
64-
verify(notificationService).createPersonalNotification(
65-
eq(testUser), // receiver (본인)
66-
eq(testUser), // actor (본인)
65+
verify(notificationService).createSelfNotification(
66+
eq(testUser), // 본인
6767
anyString(), // title
6868
anyString(), // content
69-
eq("/study/records/100")
69+
eq("/study/records/100"),
70+
eq(NotificationSettingType.SYSTEM)
7071
);
7172
}
7273

@@ -87,8 +88,8 @@ void t2() {
8788
listener.handleStudyRecordCreated(event);
8889

8990
// then
90-
verify(notificationService, never()).createPersonalNotification(
91-
any(), any(), anyString(), anyString(), anyString()
91+
verify(notificationService, never()).createSelfNotification(
92+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
9293
);
9394
}
9495

@@ -109,12 +110,12 @@ void t3() {
109110
listener.handleStudyRecordCreated(event);
110111

111112
// then
112-
verify(notificationService).createPersonalNotification(
113-
eq(testUser),
113+
verify(notificationService).createSelfNotification(
114114
eq(testUser),
115115
anyString(),
116116
anyString(),
117-
eq("/study/records/100")
117+
eq("/study/records/100"),
118+
eq(NotificationSettingType.SYSTEM)
118119
);
119120
}
120121

@@ -135,12 +136,12 @@ void t4() {
135136
listener.handleStudyRecordCreated(event);
136137

137138
// then
138-
verify(notificationService).createPersonalNotification(
139-
eq(testUser),
139+
verify(notificationService).createSelfNotification(
140140
eq(testUser),
141141
anyString(),
142142
anyString(),
143-
eq("/study/records/100")
143+
eq("/study/records/100"),
144+
eq(NotificationSettingType.SYSTEM)
144145
);
145146
}
146147

@@ -164,12 +165,12 @@ void t5() {
164165
listener.handleDailyGoalAchieved(event);
165166

166167
// then
167-
verify(notificationService).createPersonalNotification(
168-
eq(testUser), // receiver (본인)
169-
eq(testUser), // actor (본인)
168+
verify(notificationService).createSelfNotification(
169+
eq(testUser), // 본인
170170
anyString(), // title
171171
anyString(), // content
172-
eq("/study/plans?date=" + today)
172+
eq("/study/plans?date=" + today),
173+
eq(NotificationSettingType.SYSTEM)
173174
);
174175
}
175176

@@ -191,8 +192,8 @@ void t6() {
191192
listener.handleDailyGoalAchieved(event);
192193

193194
// then
194-
verify(notificationService, never()).createPersonalNotification(
195-
any(), any(), anyString(), anyString(), anyString()
195+
verify(notificationService, never()).createSelfNotification(
196+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
196197
);
197198
}
198199

@@ -214,12 +215,12 @@ void t7() {
214215
listener.handleDailyGoalAchieved(event);
215216

216217
// then
217-
verify(notificationService).createPersonalNotification(
218-
eq(testUser),
218+
verify(notificationService).createSelfNotification(
219219
eq(testUser),
220220
anyString(),
221221
anyString(),
222-
eq("/study/plans?date=" + today)
222+
eq("/study/plans?date=" + today),
223+
eq(NotificationSettingType.SYSTEM)
223224
);
224225
}
225226

@@ -241,12 +242,12 @@ void t8() {
241242
listener.handleDailyGoalAchieved(event);
242243

243244
// then
244-
verify(notificationService).createPersonalNotification(
245-
eq(testUser),
245+
verify(notificationService).createSelfNotification(
246246
eq(testUser),
247247
anyString(),
248248
anyString(),
249-
eq("/study/plans?date=" + today)
249+
eq("/study/plans?date=" + today),
250+
eq(NotificationSettingType.SYSTEM)
250251
);
251252
}
252253

@@ -268,12 +269,12 @@ void t9() {
268269
listener.handleDailyGoalAchieved(event);
269270

270271
// then
271-
verify(notificationService).createPersonalNotification(
272-
eq(testUser),
272+
verify(notificationService).createSelfNotification(
273273
eq(testUser),
274274
anyString(),
275275
anyString(),
276-
eq("/study/plans?date=" + yesterday)
276+
eq("/study/plans?date=" + yesterday),
277+
eq(NotificationSettingType.SYSTEM)
277278
);
278279
}
279280

@@ -290,16 +291,16 @@ void t10() {
290291
given(userRepository.findById(1L)).willReturn(Optional.of(testUser));
291292

292293
willThrow(new RuntimeException("알림 생성 실패"))
293-
.given(notificationService).createPersonalNotification(
294-
any(), any(), anyString(), anyString(), anyString()
294+
.given(notificationService).createSelfNotification(
295+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
295296
);
296297

297298
// when & then - 예외가 전파되지 않아야 함
298299
assertThatCode(() -> listener.handleStudyRecordCreated(event))
299300
.doesNotThrowAnyException();
300301

301-
verify(notificationService).createPersonalNotification(
302-
any(), any(), anyString(), anyString(), anyString()
302+
verify(notificationService).createSelfNotification(
303+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
303304
);
304305
}
305306

@@ -315,16 +316,16 @@ void t11() {
315316
given(userRepository.findById(1L)).willReturn(Optional.of(testUser));
316317

317318
willThrow(new RuntimeException("알림 생성 실패"))
318-
.given(notificationService).createPersonalNotification(
319-
any(), any(), anyString(), anyString(), anyString()
319+
.given(notificationService).createSelfNotification(
320+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
320321
);
321322

322323
// when & then - 예외가 전파되지 않아야 함
323324
assertThatCode(() -> listener.handleDailyGoalAchieved(event))
324325
.doesNotThrowAnyException();
325326

326-
verify(notificationService).createPersonalNotification(
327-
any(), any(), anyString(), anyString(), anyString()
327+
verify(notificationService).createSelfNotification(
328+
any(), anyString(), anyString(), anyString(), any(NotificationSettingType.class)
328329
);
329330
}
330331
}

0 commit comments

Comments
 (0)