-
Notifications
You must be signed in to change notification settings - Fork 13
/
EntityListTest.kt
122 lines (102 loc) · 2.38 KB
/
EntityListTest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package rs.dusk.engine.entity.list
import io.mockk.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import rs.dusk.engine.entity.model.Entity
import rs.dusk.engine.model.Tile
/**
* @author Greg Hibberd <greg@greghibberd.com>
* @since April 22, 2020
*/
internal class EntityListTest {
lateinit var list: EntityList<Entity>
lateinit var entity: Entity
val tile = Tile(10, 20, 1)
val hash = tile.id
@BeforeEach
fun setup() {
list = spyk(object : EntityList<Entity> {
override fun get(hash: Int): Set<Entity>? = null
override fun remove(hash: Int, entity: Entity): Boolean = true
override fun forEach(action: (Entity) -> Unit) {
}
override fun add(hash: Int, entity: Entity): Boolean = true
})
entity = mockk()
every { entity.tile } returns tile
}
@Test
fun `Get tile`() {
// When
list[tile]
// Then
verify { list[hash] }
}
@Test
fun `Get coordinates`() {
// When
list[10, 20, 1]
// Then
verifyOrder {
list[any<Tile>()]
list[hash]
}
}
@Test
fun `Add tile`() {
// When
list.add(tile, entity)
// Then
verify { list.add(hash, entity) }
}
@Test
fun `Add coordinates`() {
// When
list.add(10, 20, 1, entity)
// Then
verifyOrder {
list.add(any<Tile>(), entity)
list.add(hash, entity)
}
}
@Test
fun `Set adds`() {
// When
list[hash] = entity
// Then
verify { list.add(hash, entity) }
}
@Test
fun `Set tile`() {
// When
list[tile] = entity
// Then
verify { list.add(hash, entity) }
}
@Test
fun `Set coordinates`() {
// When
list[10, 20, 1] = entity
// Then
verifyOrder {
list.add(hash, entity)
}
}
@Test
fun `Remove tile`() {
// When
list.remove(tile, entity)
// Then
verify { list.remove(hash, entity) }
}
@Test
fun `Remove coordinates`() {
// When
list.remove(10, 20, 1, entity)
// Then
verifyOrder {
list.remove(any<Tile>(), entity)
list.remove(hash, entity)
}
}
}