mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-04-21 19:37:29 +08:00
Merge pull request #478 from nagisa77/codex/fix-postservice-argument-length-error
test: update PostService tests for new signature
This commit is contained in:
@@ -75,7 +75,8 @@ class PostControllerTest {
|
|||||||
post.setCategory(cat);
|
post.setCategory(cat);
|
||||||
post.setTags(Set.of(tag));
|
post.setTags(Set.of(tag));
|
||||||
|
|
||||||
when(postService.createPost(eq("alice"), eq(1L), eq("t"), eq("c"), eq(List.of(1L)))).thenReturn(post);
|
when(postService.createPost(eq("alice"), eq(1L), eq("t"), eq("c"), eq(List.of(1L)),
|
||||||
|
isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(post);
|
||||||
when(postService.viewPost(eq(1L), any())).thenReturn(post);
|
when(postService.viewPost(eq(1L), any())).thenReturn(post);
|
||||||
when(commentService.getCommentsForPost(eq(1L), any())).thenReturn(List.of());
|
when(commentService.getCommentsForPost(eq(1L), any())).thenReturn(List.of());
|
||||||
when(commentService.getParticipants(anyLong(), anyInt())).thenReturn(List.of());
|
when(commentService.getParticipants(anyLong(), anyInt())).thenReturn(List.of());
|
||||||
@@ -185,7 +186,8 @@ class PostControllerTest {
|
|||||||
.principal(new UsernamePasswordAuthenticationToken("alice", "p")))
|
.principal(new UsernamePasswordAuthenticationToken("alice", "p")))
|
||||||
.andExpect(status().isBadRequest());
|
.andExpect(status().isBadRequest());
|
||||||
|
|
||||||
verify(postService, never()).createPost(any(), any(), any(), any(), any());
|
verify(postService, never()).createPost(any(), any(), any(), any(), any(),
|
||||||
|
any(), any(), any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.openisle.model.*;
|
|||||||
import com.openisle.repository.*;
|
import com.openisle.repository.*;
|
||||||
import com.openisle.exception.RateLimitException;
|
import com.openisle.exception.RateLimitException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ class PostServiceTest {
|
|||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
CategoryRepository catRepo = mock(CategoryRepository.class);
|
CategoryRepository catRepo = mock(CategoryRepository.class);
|
||||||
TagRepository tagRepo = mock(TagRepository.class);
|
TagRepository tagRepo = mock(TagRepository.class);
|
||||||
|
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
|
||||||
NotificationService notifService = mock(NotificationService.class);
|
NotificationService notifService = mock(NotificationService.class);
|
||||||
SubscriptionService subService = mock(SubscriptionService.class);
|
SubscriptionService subService = mock(SubscriptionService.class);
|
||||||
CommentService commentService = mock(CommentService.class);
|
CommentService commentService = mock(CommentService.class);
|
||||||
@@ -28,11 +30,13 @@ class PostServiceTest {
|
|||||||
NotificationRepository notificationRepo = mock(NotificationRepository.class);
|
NotificationRepository notificationRepo = mock(NotificationRepository.class);
|
||||||
PostReadService postReadService = mock(PostReadService.class);
|
PostReadService postReadService = mock(PostReadService.class);
|
||||||
ImageUploader imageUploader = mock(ImageUploader.class);
|
ImageUploader imageUploader = mock(ImageUploader.class);
|
||||||
|
TaskScheduler taskScheduler = mock(TaskScheduler.class);
|
||||||
|
EmailSender emailSender = mock(EmailSender.class);
|
||||||
|
|
||||||
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo,
|
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
|
||||||
notifService, subService, commentService, commentRepo,
|
notifService, subService, commentService, commentRepo,
|
||||||
reactionRepo, subRepo, notificationRepo, postReadService,
|
reactionRepo, subRepo, notificationRepo, postReadService,
|
||||||
imageUploader, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, PublishMode.DIRECT);
|
||||||
|
|
||||||
Post post = new Post();
|
Post post = new Post();
|
||||||
post.setId(1L);
|
post.setId(1L);
|
||||||
@@ -60,6 +64,7 @@ class PostServiceTest {
|
|||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
CategoryRepository catRepo = mock(CategoryRepository.class);
|
CategoryRepository catRepo = mock(CategoryRepository.class);
|
||||||
TagRepository tagRepo = mock(TagRepository.class);
|
TagRepository tagRepo = mock(TagRepository.class);
|
||||||
|
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
|
||||||
NotificationService notifService = mock(NotificationService.class);
|
NotificationService notifService = mock(NotificationService.class);
|
||||||
SubscriptionService subService = mock(SubscriptionService.class);
|
SubscriptionService subService = mock(SubscriptionService.class);
|
||||||
CommentService commentService = mock(CommentService.class);
|
CommentService commentService = mock(CommentService.class);
|
||||||
@@ -69,15 +74,18 @@ class PostServiceTest {
|
|||||||
NotificationRepository notificationRepo = mock(NotificationRepository.class);
|
NotificationRepository notificationRepo = mock(NotificationRepository.class);
|
||||||
PostReadService postReadService = mock(PostReadService.class);
|
PostReadService postReadService = mock(PostReadService.class);
|
||||||
ImageUploader imageUploader = mock(ImageUploader.class);
|
ImageUploader imageUploader = mock(ImageUploader.class);
|
||||||
|
TaskScheduler taskScheduler = mock(TaskScheduler.class);
|
||||||
|
EmailSender emailSender = mock(EmailSender.class);
|
||||||
|
|
||||||
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo,
|
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
|
||||||
notifService, subService, commentService, commentRepo,
|
notifService, subService, commentService, commentRepo,
|
||||||
reactionRepo, subRepo, notificationRepo, postReadService,
|
reactionRepo, subRepo, notificationRepo, postReadService,
|
||||||
imageUploader, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, PublishMode.DIRECT);
|
||||||
|
|
||||||
when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L);
|
when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L);
|
||||||
|
|
||||||
assertThrows(RateLimitException.class,
|
assertThrows(RateLimitException.class,
|
||||||
() -> service.createPost("alice", 1L, "t", "c", List.of(1L)));
|
() -> service.createPost("alice", 1L, "t", "c", List.of(1L),
|
||||||
|
null, null, null, null, null, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user