test: テストを修正

This commit is contained in:
usbharu 2024-01-27 18:17:48 +09:00
parent 31240b8797
commit 72d937a104
3 changed files with 25 additions and 1 deletions

View File

@ -96,6 +96,9 @@ class EqualsAndToStringTest {
.filter {
it.superclass == Any::class.java || it.superclass?.packageName?.startsWith("dev.usbharu") ?: true
}
.filterNot {
it.superclass.isSealed
}
.filterNot { it == UnicodeEmoji::class.java }
.map {

View File

@ -4,8 +4,10 @@ package dev.usbharu.hideout.core.service.reaction
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
import dev.usbharu.hideout.core.service.notification.NotificationService
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ -18,6 +20,12 @@ import utils.PostBuilder
@ExtendWith(MockitoExtension::class)
class ReactionServiceImplTest {
@Mock
private lateinit var notificationService: NotificationService
@Mock
private lateinit var postRepository: PostRepository
@Mock
private lateinit var reactionRepository: ReactionRepository
@ -35,6 +43,9 @@ class ReactionServiceImplTest {
whenever(reactionRepository.existByPostIdAndActor(eq(post.id), eq(post.actorId))).doReturn(
false
)
whenever(postRepository.findById(eq(post.id))).doReturn(post)
whenever(reactionRepository.save(any())).doAnswer { it.arguments[0] as Reaction }
val generateId = TwitterSnowflakeIdGenerateService.generateId()
whenever(reactionRepository.generateId()).doReturn(generateId)
@ -50,7 +61,8 @@ class ReactionServiceImplTest {
whenever(reactionRepository.existByPostIdAndActor(eq(post.id), eq(post.actorId))).doReturn(
true
)
whenever(postRepository.findById(eq(post.id))).doReturn(post)
whenever(reactionRepository.save(any())).doAnswer { it.arguments[0] as Reaction }
val generateId = TwitterSnowflakeIdGenerateService.generateId()
whenever(reactionRepository.generateId()).doReturn(generateId)
@ -67,6 +79,8 @@ class ReactionServiceImplTest {
whenever(reactionRepository.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
null
)
whenever(postRepository.findById(eq(post.id))).doReturn(post)
whenever(reactionRepository.save(any())).doAnswer { it.arguments[0] as Reaction }
val generateId = TwitterSnowflakeIdGenerateService.generateId()
whenever(reactionRepository.generateId()).doReturn(generateId)
@ -83,6 +97,8 @@ class ReactionServiceImplTest {
whenever(reactionRepository.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
Reaction(id, UnicodeEmoji(""), post.id, post.actorId)
)
whenever(postRepository.findById(eq(post.id))).doReturn(post)
whenever(reactionRepository.save(any())).doAnswer { it.arguments[0] as Reaction }
val generateId = TwitterSnowflakeIdGenerateService.generateId()
whenever(reactionRepository.generateId()).doReturn(generateId)

View File

@ -10,6 +10,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.service.follow.SendFollowDto
import dev.usbharu.hideout.core.service.notification.NotificationService
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
@ -25,6 +26,10 @@ import java.net.URL
@ExtendWith(MockitoExtension::class)
class RelationshipServiceImplTest {
@Mock
private lateinit var notificationService: NotificationService
@Spy
private val applicationConfig = ApplicationConfig(URL("https://example.com"))