All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.mockk.impl.recording.ChildHinter.kt Maven / Gradle / Ivy

There is a newer version: 1.13.12
Show newest version
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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy