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

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

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))
}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy