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

com.oneeyedmen.kSera.mocking.kt Maven / Gradle / Ivy

The newest version!
package com.oneeyedmen.kSera

import org.jmock.Mockery

inline fun  Mockery.mock(): T = mock(T::class.java)
inline fun  Mockery.mock(name: String): T = mock(T::class.java, name)

fun Mockery.expecting(expectations: Expektations.() -> Unit) = this.apply {
    checking(Expektations().apply(expectations))
}

operator fun Mockery.invoke(init: BetterSyntax.() -> Unit) {
    BetterSyntax(this).init()
    assertIsSatisfied()
}

class BetterSyntax(private val mockery: Mockery) {
    private var block: (() -> Unit)? = null

    fun during(block: () -> Unit) {
        this.block = block
    }

    fun expecting(expectations: Expektations.() -> Unit) {
        mockery.expecting(expectations)
        consumeBlock()
    }

    fun verify(expectations: Expektations.() -> Unit)  = expecting(expectations)
    fun given(expectations: Expektations.() -> Unit)  = expecting(expectations)

    private fun consumeBlock() {
        block?.let {
            it()
        }
        block = null
    }

}










© 2015 - 2024 Weber Informatics LLC | Privacy Policy