commonMain.dev.mokkery.internal.matcher.capture.DefaultCapture.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mokkery-runtime Show documentation
Show all versions of mokkery-runtime Show documentation
Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
The newest version!
package dev.mokkery.internal.matcher.capture
import dev.mokkery.matcher.capture.ContainerCapture
import kotlinx.atomicfu.locks.reentrantLock
import kotlinx.atomicfu.locks.withLock
internal data class DefaultContainerCapture(
val capturedValues: MutableList = mutableListOf()
): ContainerCapture {
private val lock = reentrantLock()
override val values: List get() = lock.withLock { capturedValues.toMutableList() }
override fun capture(value: T) {
lock.withLock { capturedValues.add(value) }
}
override fun toString(): String = "container(${capturedValues.joinToString()})"
}