aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-03-02 10:34:33 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:28:14 +0100
commit1347329aa18203e9657e096447e0e30ae759b137 (patch)
tree9781a65dfed193e943e8a84a889edd8bb9c35c4e
parent8a439143252026b0bda1d1f23c688c861ae0c528 (diff)
downloaddokka-1347329aa18203e9657e096447e0e30ae759b137.tar.gz
dokka-1347329aa18203e9657e096447e0e30ae759b137.tar.bz2
dokka-1347329aa18203e9657e096447e0e30ae759b137.zip
Creates MockContext for tests
-rw-r--r--testApi/src/main/kotlin/testApi/context/MockContext.kt36
1 files changed, 36 insertions, 0 deletions
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<ExtensionPoint<*>, Any>,
+ private val testConfiguration: DokkaConfiguration? = null,
+ private val testPlatforms: Map<PlatformData, EnvironmentAndFacade>? = null
+) : DokkaContext {
+ private val extensionMap: Map<ExtensionPoint<*>, List<Any>> =
+ extensions.groupBy(Pair<ExtensionPoint<*>, Any>::first, Pair<ExtensionPoint<*>, Any>::second)
+
+ override fun <T : DokkaPlugin> plugin(kclass: KClass<T>): T? = null.also {
+ logger.warn("Cannot access plugins from mock context")
+ }
+
+ override fun <T : Any, E : ExtensionPoint<T>> get(point: E): List<T> = extensionMap[point] as List<T>
+
+ override fun <T : Any, E : ExtensionPoint<T>> 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<PlatformData, EnvironmentAndFacade>
+ get() = testPlatforms ?: throw IllegalStateException("This mock context doesn't provide platforms data")
+} \ No newline at end of file