com.oneeyedmen.kSera.mocking.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of k-sera Show documentation
Show all versions of k-sera Show documentation
A Kotlin Wrapper for JMock
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
}
}