ReflectiveStubbing

class ReflectiveStubbing<T : Any>(val self: T, kType: KType)

The receiver used to conveniently define reflective stubs on a mockK.

Constructors

Link copied to clipboard
fun <T : Any> ReflectiveStubbing(self: T, kType: KType)

Functions

Link copied to clipboard
fun answerEveryCallIn(calls: Collection<KCallable<*>>, answer: <Error class: unknown class><Any?, Any?>.(<Error class: unknown class>) -> Any?)

Convenience function to apply the same answer to every KCallable in calls

Link copied to clipboard
fun <Error class: unknown class>.callTo(callable: KCallable<*>): Any?

Convenience function to reflectively match a call to the given KCallable. callable must be a normal member function or property of self.

Link copied to clipboard
fun coAnswerEveryCallIn(calls: Collection<KCallable<*>>, answer: suspend <Error class: unknown class><Any?, Any?>.(<Error class: unknown class>) -> Any?)

Convenience function to apply the same suspendable answer to KCallable in calls

Link copied to clipboard
fun coEveryCallTo(callable: KCallable<*>): <Error class: unknown class><Any?, Any?>

Convenience function for coEvery { suspendCallTo(callable) } callable must be a suspendable member function of self.

Link copied to clipboard
fun defaultAnswer(answer: <Error class: unknown class><Any?, Any?>.(<Error class: unknown class>) -> Any?)

Convenience function to apply the same answer to every member property and function in self

Link copied to clipboard
fun everyCallTo(callable: KCallable<*>): <Error class: unknown class><Any?, Any?>

Convenience function for every { callTo(callable) } callable must be a normal member function or property of self.

Link copied to clipboard
inline fun <R> Collection<KCallable<*>>.filterReturnType(): Collection<KCallable<*>>

Convenience function to filter a collection of KCallable by return-type

Link copied to clipboard
suspend fun <Error class: unknown class>.suspendCallTo(callable: KCallable<*>): Any?

Convenience function to reflectively match a call to the given suspendable KCallable. callable must be a suspendable member function of self.

Properties

Link copied to clipboard
val kClass: KClass<*>

Convenience accessor the KClass of self. Reflective properties and functions should all come from this instance and not kType, since kType might be an interface with inaccessible methods.

Link copied to clipboard
val memberFunctions: Collection<KFunction<*>>

Convenience accessor for kotlin.reflect.full.memberFunctions via kClass

Link copied to clipboard
val memberProperties: Collection<KProperty1<*, *>>

Convenience accessor for kotlin.reflect.full.memberProperties via kClass

Link copied to clipboard
val normalMemberFunctions: Collection<KFunction<*>>

Convenience accessor for non-suspendable functions via kClass

Link copied to clipboard
val self: T

The mockK that reflective stubs are applied to.

Link copied to clipboard
val suspendMemberFunctions: Collection<KFunction<*>>

Convenience accessor for suspendable functions via kClass