kyleg
12/25/2019, 8:10 PMfoo: (File)->Long
I want to mock, and top-level (same file) caller: (foo: (File)->Long)->Int
that I do not want to mock, then that file needs @file:JvmName("FooKt") ; package <http://path.to|path.to>
up top, and then in the test:
with(::caller) {
mockkStatic("path.to.FooKt")
every { foo(any()) } returns 0L
this(::foo)
verify { foo(File("/path/to/thing") }
}
Karolis
12/30/2019, 9:52 AM@JvmName
is not neccessary if your file is called Foo.kt
since kotlin compiler will generate a class called xKt
for a file named x.kt
.kyleg
12/30/2019, 7:43 PMTo know exactly where such function as [top-level function]will land you need to check actual class files produced by the build.lowercase
Sometimes names are fancy. For example:
mockkStatic(“kotlin.io.FilesKt__UtilsKt”)
every { File(“abc”).endsWith(any<String>()) } returns true
In Kotlin there is a special directive to guide compiler what file to put such top-level functions. It is called[snip]@file:JvmName
Karolis
12/30/2019, 7:44 PMkyleg
12/30/2019, 7:45 PM