Skip to content

Commit 53727eb

Browse files
authored
Test : 테스트 수정 (#59)
1 parent f877116 commit 53727eb

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

back/src/test/java/com/back/domain/file/service/VideoServiceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.URL;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.NoSuchElementException;
2425
import java.util.UUID;
2526
import java.util.function.Consumer;
2627

@@ -103,7 +104,7 @@ void getNewsByUuidNotFoundTest() {
103104
try {
104105
videoService.getNewsByUuid(uuid);
105106
} catch (Exception e) {
106-
assertThat(e).isInstanceOf(IllegalArgumentException.class);
107+
assertThat(e).isInstanceOf(NoSuchElementException.class);
107108
assertThat(e.getMessage()).isEqualTo("존재하지 않는 비디오입니다.");
108109
}
109110
}

back/src/test/java/com/back/domain/news/comment/entity/PostCommentTest.java renamed to back/src/test/java/com/back/domain/news/comment/entity/NewsCommentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import static org.assertj.core.api.Assertions.assertThat;
1212

13-
class PostCommentTest {
13+
class NewsCommentTest {
1414
@Test
1515
@DisplayName("사용자, 뉴스, 내용으로 댓글 객체 생성")
1616
void commentCreationTest() {

back/src/test/java/com/back/domain/news/comment/service/PostCommentServiceTest.java renamed to back/src/test/java/com/back/domain/news/comment/service/NewsCommentServiceTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import org.mockito.Mock;
1515
import org.mockito.junit.jupiter.MockitoExtension;
1616

17+
import org.springframework.security.access.AccessDeniedException;
1718
import java.util.Arrays;
1819
import java.util.List;
20+
import java.util.NoSuchElementException;
1921
import java.util.Optional;
2022

2123
import static org.assertj.core.api.Assertions.assertThat;
@@ -24,7 +26,7 @@
2426
import static org.mockito.Mockito.*;
2527

2628
@ExtendWith(MockitoExtension.class)
27-
class PostCommentServiceTest {
29+
class NewsCommentServiceTest {
2830

2931
@Mock
3032
private CommentRepository commentRepository;
@@ -110,11 +112,12 @@ void updateComment_CommentNotFound_ThrowsException() {
110112
when(commentRepository.findById(nonExistentCommentId)).thenReturn(Optional.empty());
111113

112114
// when & then
113-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
115+
NoSuchElementException exception = assertThrows(NoSuchElementException.class, () -> {
114116
commentService.updateComment(member, news, nonExistentCommentId, updatedContent);
115117
});
116118

117-
assertThat(exception.getMessage()).isEqualTo("Comment not found");
119+
120+
assertThat(exception.getMessage()).isEqualTo("Comment not found: " + nonExistentCommentId);
118121
verify(commentRepository, times(1)).findById(nonExistentCommentId);
119122
}
120123

@@ -132,7 +135,7 @@ void updateComment_NotAuthor_ThrowsException() {
132135
when(commentRepository.findById(commentId)).thenReturn(Optional.of(existingComment));
133136

134137
// when & then
135-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
138+
AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> {
136139
commentService.updateComment(otherMember, news, commentId, updatedContent);
137140
});
138141

@@ -193,11 +196,11 @@ void deleteComment_CommentNotFound_ThrowsException() {
193196
when(commentRepository.findById(nonExistentCommentId)).thenReturn(Optional.empty());
194197

195198
// when & then
196-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
199+
NoSuchElementException exception = assertThrows(NoSuchElementException.class, () -> {
197200
commentService.deleteComment(member, news, nonExistentCommentId);
198201
});
199202

200-
assertThat(exception.getMessage()).isEqualTo("Comment not found");
203+
assertThat(exception.getMessage()).isEqualTo("Comment not found: " + nonExistentCommentId);
201204
verify(commentRepository, times(1)).findById(nonExistentCommentId);
202205
verify(commentRepository, never()).delete(any(Comment.class));
203206
}
@@ -215,7 +218,7 @@ void deleteComment_NotAuthor_ThrowsException() {
215218
when(commentRepository.findById(commentId)).thenReturn(Optional.of(existingComment));
216219

217220
// when & then
218-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
221+
AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> {
219222
commentService.deleteComment(otherMember, news, commentId);
220223
});
221224

0 commit comments

Comments
 (0)