I've added a couple helper functions for mockk. ``...
# detekt
e
I've added a couple helper functions for mockk.
Copy code
fun verifyOnce(
    ordering: Ordering = Ordering.UNORDERED,
    inverse: Boolean = false,
    timeout: Long = 0,
    verifyBlock: MockKVerificationScope.() -> Unit,
) = verify(ordering = ordering, inverse = inverse, exactly = 1, timeout = timeout, verifyBlock = verifyBlock)
If I write it like that ^ then running w/ type resolution fails due to
ImplicitUnitReturnType
Copy code
fun verifyOnce(
    ordering: Ordering = Ordering.UNORDERED,
    inverse: Boolean = false,
    timeout: Long = 0,
    verifyBlock: MockKVerificationScope.() -> Unit,
): Unit = verify(ordering = ordering, inverse = inverse, exactly = 1, timeout = timeout, verifyBlock = verifyBlock)
If I write it like that ^ then w/o type resolution it fails due to
OptionalUnit
What should I do in a situation like this? Just suppress one or the other? Which one?
I suppose this works w/o any suppression:
Copy code
fun verifyOnce(
    ordering: Ordering = Ordering.UNORDERED,
    inverse: Boolean = false,
    timeout: Long = 0,
    verifyBlock: MockKVerificationScope.() -> Unit,
) {
    verify(ordering = ordering, inverse = inverse, exactly = 1, timeout = timeout, verifyBlock = verifyBlock)
}
b
I would vote to don't use the
=
notation when you return
Unit
. It's counter intuitive. Use the good old
{}
e
yeah, that's what i went with