com.oneeyedmen.kSera.Expektations.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 com.natpryce.hamkrest.Matcher
import org.jmock.Expectations
import org.jmock.Sequence
import org.jmock.api.Invocation
import kotlin.reflect.KProperty1
@Suppress("unused")
class Expektations: Expectations() {
inline fun with(matcher: Matcher): T {
addParameterMatcher(matcher.asHamcrest())
return dummyValueOfType(T::class)
}
val T.which: WillThunker get() = WillThunker()
infix fun WillThunker.will(action: TypedAction) = super.will(action)
infix fun WillThunker.will(block: (Invocation) -> T) = super.will(invoke("invoke a block", block))
infix fun WillThunker.willDo(block: Invocation.() -> T) = will(block)
fun Any?.inSequence(sequence: Sequence) = super.inSequence(sequence)
class WillThunker() // required to make the types work, see http://stackoverflow.com/q/39596420/97777
fun that(mock: T, property: KProperty1) = property.get(allowing(mock))
val T.isProperty: PropertyThunker get() = PropertyThunker()
class PropertyThunker()
infix fun PropertyThunker.withValue(value: T) = super.will(com.oneeyedmen.kSera.returnValue(value))
}