Skip to content

Commit c9a866d

Browse files
committed
refactor: 코드 리뷰 테스트 수정
1 parent ceb915b commit c9a866d

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

src/main/java/com/somemore/notification/repository/NotificationRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public interface NotificationRepository {
1818

1919
List<Notification> findByReceiverIdAndUnread(UUID userId);
2020
List<Notification> findByReceiverIdAndRead(UUID userId);
21+
22+
void deleteAllInBatch();
2123
}

src/main/java/com/somemore/notification/repository/NotificationRepositoryImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public List<Notification> findByReceiverIdAndRead(UUID receiverId) {
5151
.fetch();
5252
}
5353

54+
@Override
55+
public void deleteAllInBatch() {
56+
notificationJpaRepository.deleteAllInBatch();
57+
}
58+
5459
private static BooleanExpression eqReceiverId(UUID userId) {
5560
return notification.receiverId.eq(userId);
5661
}

src/test/java/com/somemore/notification/repository/NotificationRepositoryTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,8 @@ void setup() {
3232
savedNotificationIds = new ArrayList<>();
3333

3434
for (long i = 1; i <= 10; i++) {
35-
Notification unreadNotification = Notification.builder()
36-
.title("Unread Notification")
37-
.type(NotificationSubType.NOTE_BLAH_BLAH)
38-
.receiverId(receiverId)
39-
.relatedId(i + 1)
40-
.build();
41-
42-
Notification readNotification = Notification.builder()
43-
.title("Read Notification")
44-
.type(NotificationSubType.REVIEW_BLAH_BLAH)
45-
.receiverId(receiverId)
46-
.relatedId(i + 100)
47-
.build();
48-
49-
readNotification.markAsRead();
35+
Notification unreadNotification = createNotification(i, false);
36+
Notification readNotification = createNotification(i * 100, true);
5037

5138
notificationRepository.save(unreadNotification);
5239
notificationRepository.save(readNotification);
@@ -63,7 +50,6 @@ void findByReceiverIdAndUnread() {
6350

6451
// then
6552
assertThat(notifications).hasSize(10);
66-
assertThat(notifications.getFirst().getTitle()).isEqualTo("Unread Notification");
6753
assertThat(notifications.getFirst().isRead()).isFalse();
6854
}
6955

@@ -75,7 +61,6 @@ void findByReceiverIdAndRead() {
7561

7662
// then
7763
assertThat(notifications).hasSize(10);
78-
assertThat(notifications.getFirst().getTitle()).isEqualTo("Read Notification");
7964
assertThat(notifications.getFirst().isRead()).isTrue();
8065
}
8166

@@ -107,10 +92,26 @@ void findById() {
10792
@Test
10893
void findAllByIds() {
10994
// given
95+
notificationRepository.deleteAllInBatch();
96+
11097
// when
11198
List<Notification> notifications = notificationRepository.findAllByIds(savedNotificationIds);
11299

113100
// then
114-
assertThat(notifications).hasSize(10);
101+
assertThat(notifications).isEmpty();
102+
}
103+
104+
private Notification createNotification(long i, boolean isRead) {
105+
Notification notification = Notification.builder()
106+
.title("Notification")
107+
.type(NotificationSubType.NOTE_BLAH_BLAH)
108+
.receiverId(receiverId)
109+
.relatedId(i + 1)
110+
.build();
111+
112+
if (isRead) {
113+
notification.markAsRead();
114+
}
115+
return notification;
115116
}
116117
}

src/test/java/com/somemore/notification/service/NotificationCommandServiceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.somemore.notification.service;
22

33
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_NOTIFICATION;
4+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_NOTIFICATION;
45
import static org.assertj.core.api.Assertions.assertThat;
56
import static org.assertj.core.api.Assertions.assertThatThrownBy;
67

@@ -69,7 +70,7 @@ void markSingleNotificationAsReadWhenUnauthorized() {
6970
// when / then
7071
assertThatThrownBy(() -> notificationCommandService.markSingleNotificationAsRead(receiverId, notification.getId()))
7172
.isInstanceOf(BadRequestException.class)
72-
.hasMessageContaining("권한이 없습니다");
73+
.hasMessageContaining(UNAUTHORIZED_NOTIFICATION.getMessage());
7374
}
7475

7576
@DisplayName("알림 N개를 읽음 처리한다.")
@@ -118,7 +119,7 @@ void markMultipleNotificationsAsReadWhenUnauthorized() {
118119
// when / then
119120
assertThatThrownBy(() -> notificationCommandService.markMultipleNotificationsAsRead(receiverId, requestDto))
120121
.isInstanceOf(BadRequestException.class)
121-
.hasMessageContaining("권한이 없습니다");
122+
.hasMessageContaining(UNAUTHORIZED_NOTIFICATION.getMessage());
122123
}
123124

124125
private Notification createNotification(UUID receiverId) {

0 commit comments

Comments
 (0)