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

io.mockk.impl.recording.states.AnsweringState.kt Maven / Gradle / Ivy

package io.mockk.impl.recording.states

import io.mockk.InternalPlatformDsl.toStr
import io.mockk.Invocation
import io.mockk.MockKGateway.VerificationParameters
import io.mockk.impl.log.Logger
import io.mockk.impl.recording.CommonCallRecorder

open class AnsweringState(recorder: CommonCallRecorder) : CallRecordingState(recorder) {
    open val log = recorder.safeLog(Logger())

    override fun call(invocation: Invocation): Any? {
        val stub = recorder.stubRepo.stubFor(invocation.self)
        stub.recordCall(invocation.copy(originalCall = { null }))
        val answer = stub.answer(invocation)
        log.info { "Answering ${answer.toStr()} on $invocation" }
        return answer
    }

    override fun startStubbing() = recorder.factories.stubbingState(recorder)
    override fun startVerification(params: VerificationParameters) = recorder.factories.verifyingState(recorder, params)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy