forked from mockk/mockk
/
MockAbstractArgTest.kt
51 lines (37 loc) · 1.27 KB
/
MockAbstractArgTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package io.mockk.ait
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.mockk.mockk
import io.mockk.verify
import org.junit.runner.RunWith
import kotlin.test.Test
abstract class MyAbstractClass
interface IOtherInterface {}
interface IMockableInterface {
fun doSomethingWithAbstractClass(a: MyAbstractClass?)
fun doSomethingWithInterface(a: IOtherInterface?)
fun doSomethingWithString(s: String)
}
@RunWith(AndroidJUnit4::class)
class MockAbstractArgTest {
@Test
fun canVerifyStringArg() {
val myMock = mockk<IMockableInterface>(relaxUnitFun = true)
myMock.doSomethingWithString("hello")
// works
verify { myMock.doSomethingWithString(any()) }
}
@Test
fun cannotVerifyAbstractArg() {
val myMock = mockk<IMockableInterface>(relaxUnitFun = true)
myMock.doSomethingWithAbstractClass(null)
// JNI DETECTED ERROR IN APPLICATION: can't make objects of type com.test.MyAbstractClass
verify { myMock.doSomethingWithAbstractClass(any()) }
}
@Test
fun canVerifyInterfaceArg() {
val myMock = mockk<IMockableInterface>(relaxUnitFun = true)
myMock.doSomethingWithInterface(null)
// works
verify { myMock.doSomethingWithInterface(any()) }
}
}