From c63ea36637ce956029fb15b1482c0683ecb8a587 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Wed, 30 Aug 2023 15:58:46 +0200 Subject: Migrate to JUnit 5 and unify used test API (#3138) --- .../ResolveLinkGfmCommandResolutionTest.kt | 90 +++++++++++----------- 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt') diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt index b38fb03f..9bb6ee89 100644 --- a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt +++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt @@ -8,67 +8,65 @@ import org.jetbrains.dokka.gfm.GfmPlugin import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand import org.jetbrains.dokka.gfm.templateProcessing.GfmTemplateProcessingPlugin import org.jetbrains.dokka.links.DRI -import org.junit.Rule -import org.junit.jupiter.api.Test -import org.junit.rules.TemporaryFolder +import org.junit.jupiter.api.io.TempDir import java.io.File +import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() { - @get:Rule - val folder: TemporaryFolder = TemporaryFolder() - private fun configuration() = dokkaConfiguration { - modules = listOf( - DokkaModuleDescriptionImpl( - name = "module1", - relativePathToOutputDirectory = folder.root.resolve("module1"), - includes = emptySet(), - sourceOutputDirectory = folder.root.resolve("module1"), - ), - DokkaModuleDescriptionImpl( - name = "module2", - relativePathToOutputDirectory = folder.root.resolve("module2"), - includes = emptySet(), - sourceOutputDirectory = folder.root.resolve("module2"), + @Test + fun `should resolve link to another module`(@TempDir outputDirectory: File) { + val configuration = dokkaConfiguration { + modules = listOf( + DokkaModuleDescriptionImpl( + name = "module1", + relativePathToOutputDirectory = outputDirectory.resolve("module1"), + includes = emptySet(), + sourceOutputDirectory = outputDirectory.resolve("module1"), + ), + DokkaModuleDescriptionImpl( + name = "module2", + relativePathToOutputDirectory = outputDirectory.resolve("module2"), + includes = emptySet(), + sourceOutputDirectory = outputDirectory.resolve("module2"), + ) ) - ) - outputDir = folder.root - } + outputDir = outputDirectory + } - @Test - fun `should resolve link to another module`(){ - val testedDri = DRI( - packageName = "package2", - classNames = "Sample", - ) + val innerModule1 = outputDirectory.resolve("module1").also { assertTrue(it.mkdirs()) } + val innerModule2 = outputDirectory.resolve("module2").also { assertTrue(it.mkdirs()) } + + val indexMd = innerModule1.resolve("index.md") + val packageList = innerModule2.resolve("package-list") - val link = StringBuilder().apply { - templateCommand(ResolveLinkGfmCommand(testedDri)){ + val indexMdContent = StringBuilder().apply { + templateCommand( + ResolveLinkGfmCommand( + dri = DRI( + packageName = "package2", + classNames = "Sample", + ) + ) + ) { append("Sample text inside") } }.toString() - val expected = "[Sample text inside](../module2/package2/-sample/index.md)" - - val content = setup(link) - val configuration = configuration() + indexMd.writeText(indexMdContent) + packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaGFM, "package2")) - testFromData(configuration, pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), useOutputLocationFromConfig = true) { + testFromData( + configuration, + pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), + useOutputLocationFromConfig = true + ) { finishProcessingSubmodules = { - assertEquals(expected, content.readText().trim()) + val expectedIndexMd = "[Sample text inside](../module2/package2/-sample/index.md)" + assertEquals(expectedIndexMd, indexMd.readText().trim()) } } } - - private fun setup(content: String): File { - folder.create() - val innerModule1 = folder.newFolder( "module1") - val innerModule2 = folder.newFolder( "module2") - val packageList = innerModule2.resolve("package-list") - packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaGFM, "package2")) - val contentFile = innerModule1.resolve("index.md") - contentFile.writeText(content) - return contentFile - } } -- cgit