Last active
April 3, 2017 17:46
-
-
Save mg6maciej/df93c5a46a218cc0ab0e0a20cc79bc1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> stubbable(function: KCallable<T>) = object : ReadWriteProperty<Any?, T> { | |
override fun getValue(thisRef: Any?, property: KProperty<*>) = throw UnsupportedOperationException() | |
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { | |
val args = listOf(thisRef) + function.parameters.drop(1).map { anyList<Any>() } | |
whenever(function.call(*args.toTypedArray())).thenReturn(value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment