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

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

There is a newer version: 1.13.12
Show newest version
package io.mockk.impl.recording

import io.mockk.Invocation
import io.mockk.Matcher
import io.mockk.impl.log.SafeToString
import kotlin.reflect.KClass

class CallRoundBuilder(val safeToString: SafeToString) {
    val signedMatchers = mutableListOf()
    val signedCalls = mutableListOf()

    fun addMatcher(matcher: Matcher<*>, sigValue: Any) {
        signedMatchers.add(SignedMatcher(matcher, sigValue))
    }

    fun addSignedCall(
        retValue: Any?,
        tempMock: Boolean,
        retType: KClass<*>,
        invocation: Invocation
    ) {
        val signedCall = SignedCall(
            retValue,
            tempMock,
            retType,
            invocation.self,
            invocation.method,
            invocation.args,
            safeToString.exec { invocation.toString() }
        )

        signedCalls.add(signedCall)
    }

    fun addWasNotCalled(list: List) {
        for (self in list) {
            signedCalls.add(
                SignedCall(
                    Unit,
                    false,
                    Unit::class,
                    self,
                    WasNotCalled.method,
                    listOf(),
                    safeToString.exec { "$self wasNot Called" }
                )
            )
        }
    }

    fun build() = CallRound(signedCalls.toList(), signedMatchers.toList())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy