test: postのテストを追加

This commit is contained in:
usbharu 2024-06-06 14:15:59 +09:00
parent c84517908e
commit 6739bb0da2
1 changed files with 46 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import org.junit.jupiter.api.assertThrows
import utils.AssertDomainEvent.assertContainsEvent import utils.AssertDomainEvent.assertContainsEvent
import utils.AssertDomainEvent.assertEmpty import utils.AssertDomainEvent.assertEmpty
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNull
class PostTest { class PostTest {
@Test @Test
@ -210,5 +211,50 @@ class PostTest {
assertContainsEvent(post, PostEvent.update.eventName) assertContainsEvent(post, PostEvent.update.eventName)
} }
@Test
fun hideがtrueの時nullを返す() {
val post = TestPostFactory.create(hide = true, overview = "aaaa")
assertNull(post.overview)
}
@Test
fun hideがfalseの時overviewを返す() {
val post = TestPostFactory.create(hide = false, overview = "aaaa")
assertEquals(PostOverview("aaaa"), post.overview)
}
@Test
fun deletedがtrueのときセットできない() {
val post = TestPostFactory.create(deleted = true)
assertThrows<IllegalArgumentException> {
post.overview = PostOverview("aaaa")
}
}
@Test
fun deletedがfalseのときセットできる() {
val post = TestPostFactory.create(deleted = false)
val overview = PostOverview("aaaa")
assertDoesNotThrow {
post.overview = overview
}
assertEquals(overview, post.overview)
assertContainsEvent(post, PostEvent.update.eventName)
}
@Test
fun overviewの内容が更新されなかった時イベントが発生しない() {
val post = TestPostFactory.create(overview = "aaaa")
post.overview = PostOverview("aaaa")
assertEmpty(post)
}
} }