test: update PostService tests for new signature

This commit is contained in:
Tim
2025-08-11 10:06:53 +08:00
parent e27f57fab2
commit 36bc86da7f
2 changed files with 17 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import com.openisle.model.*;
import com.openisle.repository.*;
import com.openisle.exception.RateLimitException;
import org.junit.jupiter.api.Test;
import org.springframework.scheduling.TaskScheduler;
import static org.junit.jupiter.api.Assertions.*;
@@ -19,6 +20,7 @@ class PostServiceTest {
UserRepository userRepo = mock(UserRepository.class);
CategoryRepository catRepo = mock(CategoryRepository.class);
TagRepository tagRepo = mock(TagRepository.class);
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
NotificationService notifService = mock(NotificationService.class);
SubscriptionService subService = mock(SubscriptionService.class);
CommentService commentService = mock(CommentService.class);
@@ -28,11 +30,13 @@ class PostServiceTest {
NotificationRepository notificationRepo = mock(NotificationRepository.class);
PostReadService postReadService = mock(PostReadService.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,
reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, PublishMode.DIRECT);
imageUploader, taskScheduler, emailSender, PublishMode.DIRECT);
Post post = new Post();
post.setId(1L);
@@ -60,6 +64,7 @@ class PostServiceTest {
UserRepository userRepo = mock(UserRepository.class);
CategoryRepository catRepo = mock(CategoryRepository.class);
TagRepository tagRepo = mock(TagRepository.class);
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
NotificationService notifService = mock(NotificationService.class);
SubscriptionService subService = mock(SubscriptionService.class);
CommentService commentService = mock(CommentService.class);
@@ -69,15 +74,18 @@ class PostServiceTest {
NotificationRepository notificationRepo = mock(NotificationRepository.class);
PostReadService postReadService = mock(PostReadService.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,
reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, PublishMode.DIRECT);
imageUploader, taskScheduler, emailSender, PublishMode.DIRECT);
when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L);
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));
}
}