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

commonTest.utils.RecordingConsumer.kt Maven / Gradle / Ivy

package kt.mobius

import kt.mobius.functions.Consumer
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class RecordingConsumer : Consumer {

    private val values = arrayListOf()

    private object LOCK

    override fun accept(value: V): Unit =
        mpp.synchronized(LOCK) {
            values.add(value)
        }

    fun valueCount(): Int =
        mpp.synchronized(LOCK) {
            values.size
        }

    fun assertValues(vararg expectedValues: V): Unit =
        mpp.synchronized(LOCK) {
            assertEquals(values, expectedValues.asList())
        }

    fun assertValuesInAnyOrder(vararg expectedValues: V): Unit =
        mpp.synchronized(LOCK) {
            assertTrue(values.containsAll(expectedValues.toList()))
        }

    fun clearValues(): Unit =
        mpp.synchronized(LOCK) {
            values.clear()
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy