From 1347329aa18203e9657e096447e0e30ae759b137 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Mon, 2 Mar 2020 10:34:33 +0100 Subject: Creates MockContext for tests --- .../src/main/kotlin/testApi/context/MockContext.kt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 testApi/src/main/kotlin/testApi/context/MockContext.kt (limited to 'testApi/src') diff --git a/testApi/src/main/kotlin/testApi/context/MockContext.kt b/testApi/src/main/kotlin/testApi/context/MockContext.kt new file mode 100644 index 00000000..4f481bce --- /dev/null +++ b/testApi/src/main/kotlin/testApi/context/MockContext.kt @@ -0,0 +1,36 @@ +package org.jetbrains.dokka.testApi.context + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.EnvironmentAndFacade +import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.plugability.ExtensionPoint +import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import kotlin.reflect.KClass + +@Suppress("UNCHECKED_CAST") // It is only usable from tests so we do not care about safety +class MockContext( + vararg extensions: Pair, Any>, + private val testConfiguration: DokkaConfiguration? = null, + private val testPlatforms: Map? = null +) : DokkaContext { + private val extensionMap: Map, List> = + extensions.groupBy(Pair, Any>::first, Pair, Any>::second) + + override fun plugin(kclass: KClass): T? = null.also { + logger.warn("Cannot access plugins from mock context") + } + + override fun > get(point: E): List = extensionMap[point] as List + + override fun > single(point: E): T = get(point).single() + + override val logger = DokkaConsoleLogger + + override val configuration: DokkaConfiguration + get() = testConfiguration ?: throw IllegalStateException("This mock context doesn't provide configuration") + + override val platforms: Map + get() = testPlatforms ?: throw IllegalStateException("This mock context doesn't provide platforms data") +} \ No newline at end of file -- cgit