From b76e1d19a5aaf31d39f9b7042d56962f480f2472 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:16:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20suspend=E3=81=A7=E3=81=AA=E3=81=84?= =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/DefaultPostContentFormatter.kt | 4 +++- .../core/service/post/PostContentFormatter.kt | 2 +- .../post/DefaultPostContentFormatterTest.kt | 23 +++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt index 49548f8e..fcf52fad 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt @@ -6,9 +6,11 @@ import org.jsoup.nodes.Element import org.jsoup.nodes.TextNode import org.jsoup.parser.Tag import org.jsoup.select.Elements +import org.springframework.stereotype.Service +@Service class DefaultPostContentFormatter() : PostContentFormatter { - override suspend fun format(content: String): FormattedPostContent { + override fun format(content: String): FormattedPostContent { val document = Jsoup.parseBodyFragment(content).getElementsByTag("body").first() ?: return FormattedPostContent("", "") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt index 7713adea..543bba26 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt @@ -1,5 +1,5 @@ package dev.usbharu.hideout.core.service.post interface PostContentFormatter { - suspend fun format(content: String): FormattedPostContent + fun format(content: String): FormattedPostContent } diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatterTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatterTest.kt index 7ac2e857..ef5ac49b 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatterTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatterTest.kt @@ -1,12 +1,11 @@ package dev.usbharu.hideout.core.service.post -import kotlinx.coroutines.test.runTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test class DefaultPostContentFormatterTest { @Test - fun pタグがpタグになる() = runTest { + fun pタグがpタグになる() { //language=HTML val html = """
hoge
""" @@ -16,7 +15,7 @@ class DefaultPostContentFormatterTest { } @Test - fun hタグがpタグになる() = runTest { + fun hタグがpタグになる() { //language=HTML val html = """hoge
fuga
piyo""" @@ -36,7 +35,7 @@ class DefaultPostContentFormatterTest { } @Test - fun spanタグは無視される() = runTest { + fun spanタグは無視される() { //language=HTML val html = """hoge
""" @@ -46,7 +45,7 @@ class DefaultPostContentFormatterTest { } @Test - fun `2連続改行は段落に変換される`() = runTest { + fun `2連続改行は段落に変換される`() { //language=HTML val html = """hoge
fuga
hoge
""" @@ -66,7 +65,7 @@ class DefaultPostContentFormatterTest { } @Test - fun aタグはhrefの中身のみ引き継がれる() = runTest { + fun aタグはhrefの中身のみ引き継がれる() { //language=HTML val html = """""" @@ -76,7 +75,7 @@ class DefaultPostContentFormatterTest { } @Test - fun aタグの中のspanは無視される() = runTest { + fun aタグの中のspanは無視される() { //language=HTML val html = """""" @@ -86,7 +85,7 @@ class DefaultPostContentFormatterTest { } @Test - fun brタグのコンテンツは改行になる() = runTest { + fun brタグのコンテンツは改行になる() { //language=HTML val html = """hoge
fuga