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

commonMain.io.mockk.impl.stub.CommonClearer.kt Maven / Gradle / Ivy

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

import io.mockk.MockKGateway
import io.mockk.MockKGateway.Clearer
import io.mockk.impl.log.Logger
import io.mockk.impl.log.SafeToString

class CommonClearer(
    val stubRepository: StubRepository,
    val safeToString: SafeToString
) : Clearer {
    val log = safeToString(Logger())

    override fun clear(mocks: Array, options: MockKGateway.ClearOptions) {
        log.debug { "Clearing ${mocks.contentToString()} mocks $options" }
        for (mock in mocks) {
            stubRepository.stubFor(mock).clear(options)
        }
    }

    override fun clearAll(options: MockKGateway.ClearOptions, currentThreadOnly: Boolean) {
        val currentThreadId = Thread.currentThread().id
        stubRepository.allStubs.forEach {
            if (currentThreadOnly && currentThreadId != it.threadId) {
                return@forEach
            }
            it.clear(options)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy