Is there any way to mock a extension function with...
# spek
d
Is there any way to mock a extension function with Mockito?
t
Perhaps instead of mocking you could re-define the extension method, taking advantage of how kotlin resolves them?
For example, if you have this in `Extensions.kt`:
Copy code
fun String.doSomething(): String = this.reversed()
And then you could override that in your test method because you can define local functions...
Copy code
fun mocked() {
    fun String.doSomething(): String = this.toUpperCase()
    println("abc".doSomething())
}
That way, when you call
doSomething()
in
mocked()
, it uses the version closest in scope to it (which will uppercase it in this example)
d
If I redefine it in my test, and class A which I'm testing is using the one from the import, then it still gets overridden with the one in the test?
A is my SUT
t
Ah, my bad. I totally misread your question. I'm sorry.