anthonycr / Mockingbird

A minimalist faking framework exclusively for verifying interactions
MIT License
3 stars 2 forks source link

Improve parameter verification support #16

Closed anthonycr closed 6 months ago

anthonycr commented 6 months ago

Currently, verifying parameters looks like this

verify(myInterface) {
     myInterface.verifyParams(
         verifier = { (it[0] as? Exception)?.message == "test" },
         invocation = { performAction(Exception("test")) }
    )
}

This feels too awkward and requires force casting the parameters. A better way that requires writing more code and potentially generating some functions is

verify(myInterface) {
    myInterface.verifyParams(
        func = MyInterface::performAction
        param0 = eq(Exception("test")) { it.message == "test" }
    )
}

I'll need to create a number of iterations of the verifyParams function to match this signature

fun <T, P> T.verifyParams(
    func: T.(P) -> Unit,
    param0: Pair<P, (P) -> Boolean>
)

The benefit of this is that type changes to a parameter will fail to compile instead of being runtime validated.