commonMain.io.mockk.impl.recording.ChildHinter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockk-jvm Show documentation
Show all versions of mockk-jvm Show documentation
Mocking library for Kotlin
package io.mockk.impl.recording
import kotlin.reflect.KClass
class ChildHinter {
private var childTypes = mutableMapOf>()
fun nextChildType(defaultReturnType: () -> KClass<*>): KClass<*> {
val type = childTypes[1]
shift()
return type ?: defaultReturnType()
}
private fun shift() {
childTypes = childTypes
.mapKeys { (k, _) -> k - 1 }
.filter { (k, _) -> k > 0 }
.toMutableMap()
}
fun hint(n: Int, cls: KClass<*>) {
childTypes[n] = cls
}
}