Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/main/kotlin/dev/sunabak0/akiyadego/domain/Post.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.sunabak0.akiyadego.domain

/**
* 投稿
*
* @property id
* @property imagePath
* @property title
* @property category
* @property prefecture
* @property description
* @property userId
* @property createdAt
* @constructor Create empty Post
*/
data class Post(
val id: Int,
val imagePath: String,
val title: String,
val category: String,
val prefecture: String,
val description: String,
val userId: Int,
val createdAt: String,
) {
/**
* Factory メソッド
*/
companion object {
/**
* Validation 有り
*/
fun new(
id: Int,
imagePath: String,
title: String,
category: String,
prefecture: String,
description: String,
userId: Int,
createdAt: String,
): Post {
if (title.isEmpty()) {
return IllegalArgumentException("タイトルが1文字未満です")
}
return Post(id, imagePath, title, category, prefecture, description, userId, createdAt)
}
}
}
28 changes: 28 additions & 0 deletions src/test/kotlin/dev/sunabak0/akiyadego/domain/PostTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.sunabak0.akiyadego.domain

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

class PostTest {
@Test
fun `投稿のタイトルの文字数が違反していたら投稿の生成に失敗する`() {
/**
* given:
*/

/**
* when:
* -
*/

/**
* then:
* - タイトルを検査
*/
val e = assertThrows<IllegalArgumentException> {
Post.new(1, "/path", "", "akiya", "tokyo", "空き家の説明", 1, "20230117-12:00:00")
}
assertEquals(e.message, "タイトルが1文字未満です")
}
}