diff options
Diffstat (limited to 'plugins/all-modules-page')
4 files changed, 88 insertions, 94 deletions
diff --git a/plugins/all-modules-page/build.gradle.kts b/plugins/all-modules-page/build.gradle.kts index 191f2433..c546f73c 100644 --- a/plugins/all-modules-page/build.gradle.kts +++ b/plugins/all-modules-page/build.gradle.kts @@ -20,12 +20,11 @@ dependencies { implementation(libs.kotlinx.html) + testImplementation(kotlin("test")) testImplementation(projects.plugins.base) testImplementation(projects.plugins.base.baseTestUtils) testImplementation(projects.plugins.gfm) testImplementation(projects.plugins.gfm.gfmTemplateProcessing) testImplementation(projects.core.contentMatcherTestUtils) testImplementation(projects.core.testApi) - testImplementation(platform(libs.junit.bom)) - testImplementation(libs.junit.jupiter) } diff --git a/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt index 525331fc..a92fa115 100644 --- a/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt +++ b/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt @@ -6,37 +6,37 @@ import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentResolvedLink import org.jetbrains.dokka.pages.MultimoduleRootPageNode -import org.junit.Rule -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -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.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test import kotlin.test.assertEquals class MultiModuleDocumentationTest : MultiModuleAbstractTest() { - @get:Rule - val folder: TemporaryFolder = TemporaryFolder() + + @field:TempDir + lateinit var tempDir: File val documentationContent = """ # Sample project Sample documentation with [external link](https://www.google.pl) """.trimIndent() - @BeforeEach + @BeforeTest fun setup() { - folder.create() - folder.root.resolve("README.md").writeText(documentationContent) + tempDir.resolve("README.md").writeText(documentationContent) } - @AfterEach + @AfterTest fun teardown(){ - folder.root.resolve("README.md").delete() + tempDir.resolve("README.md").delete() } @Test fun `documentation should be included in all modules page`() { val configuration = dokkaConfiguration { - includes = listOf(folder.root.resolve("README.md")) + includes = listOf(tempDir.resolve("README.md")) } testFromData(configuration) { diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt index 7ef8c3ea..5e785e03 100644 --- a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt +++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt @@ -9,36 +9,16 @@ import org.jetbrains.dokka.base.renderers.html.templateCommand import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.base.templating.ResolveLinkCommand 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 utils.assertHtmlEqualsIgnoringWhitespace import java.io.File +import kotlin.test.Test +import kotlin.test.assertTrue class ResolveLinkCommandResolutionTest : 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"), - ) - ) - this.outputDir = folder.root - } @Test - fun `should resolve link to another module`() { + fun `should resolve link to another module`(@TempDir outputDirectory: File) { val testedDri = DRI( packageName = "package2", classNames = "Sample", @@ -56,8 +36,8 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { } } - val contentFile = setup(link) - val configuration = configuration() + val contentFile = setup(outputDirectory, link) + val configuration = createConfiguration(outputDirectory) testFromData(configuration, useOutputLocationFromConfig = true) { finishProcessingSubmodules = { @@ -67,7 +47,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { } @Test - fun `should produce content when link is not resolvable`() { + fun `should produce content when link is not resolvable`(@TempDir outputDirectory: File) { val testedDri = DRI( packageName = "not-resolvable-package", classNames = "Sample", @@ -85,8 +65,8 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { } } - val contentFile = setup(link) - val configuration = configuration() + val contentFile = setup(outputDirectory, link) + val configuration = createConfiguration(outputDirectory) testFromData(configuration, useOutputLocationFromConfig = true) { finishProcessingSubmodules = { @@ -95,14 +75,31 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { } } - fun setup(content: String): File { - folder.create() - val innerModule1 = folder.newFolder("module1") - val innerModule2 = folder.newFolder("module2") + private fun setup(outputDirectory: File, content: String): File { + val innerModule1 = outputDirectory.resolve("module1").also { assertTrue(it.mkdirs()) } + val innerModule2 = outputDirectory.resolve("module2").also { assertTrue(it.mkdirs()) } val packageList = innerModule2.resolve("package-list") packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaHtml, "package2")) val contentFile = innerModule1.resolve("index.html") contentFile.writeText(content) return contentFile } + + private fun createConfiguration(outputDirectory: File) = 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"), + ) + ) + this.outputDir = outputDirectory + } } 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 - } } |