/
CollectionChainStubbingTest.kt
68 lines (53 loc) · 1.5 KB
/
CollectionChainStubbingTest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package io.mockk.it
import io.mockk.every
import io.mockk.mockk
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
// Regression tests for GitHub issue #565.
class CollectionChainStubbingTest {
private interface ReturningCollections {
val list: List<Int>
val map: Map<String, Int>
val set: Set<Int>
val arrayList: ArrayList<Int>
val hashMap: Map<String, Int>
val hashSet: HashSet<Int>
}
@Test
fun list() {
val mock = mockk<ReturningCollections>()
every { mock.list[0] } returns 1
assertEquals(1, mock.list[0])
}
@Test
fun map() {
val mock = mockk<ReturningCollections>()
every { mock.map["foo"] } returns 1
assertEquals(1, mock.map["foo"])
}
@Test
fun set() {
val mock = mockk<ReturningCollections>()
every { mock.set.contains(1) } returns true
assertTrue(mock.set.contains(1))
}
@Test
fun arrayList() {
val mock = mockk<ReturningCollections>()
every { mock.arrayList[0] } returns 1
assertEquals(1, mock.arrayList[0])
}
@Test
fun hashMap() {
val mock = mockk<ReturningCollections>()
every { mock.hashMap["foo"] } returns 1
assertEquals(1, mock.hashMap["foo"])
}
@Test
fun hashSet() {
val mock = mockk<ReturningCollections>()
every { mock.hashSet.contains(0) } returns true
assertTrue(mock.hashSet.contains(0))
}
}