@@ -27,18 +27,24 @@ import kotlinx.coroutines.delay
27
27
import kotlinx.coroutines.launch
28
28
import kotlinx.coroutines.withTimeoutOrNull
29
29
import kotlinx.coroutines.yield
30
+ import java.util.UUID
30
31
31
32
// Mocks used by every test in this file
32
33
private class Mocks {
33
34
val configModelStore = MockHelper .configModelStore()
34
35
35
36
val operationModelStore: OperationModelStore =
36
37
run {
38
+ val operationStoreList = mutableListOf<Operation >()
37
39
val mockOperationModelStore = mockk<OperationModelStore >()
38
40
every { mockOperationModelStore.loadOperations() } just runs
39
- every { mockOperationModelStore.list() } returns listOf ()
40
- every { mockOperationModelStore.add(any()) } just runs
41
- every { mockOperationModelStore.remove(any()) } just runs
41
+ every { mockOperationModelStore.list() } returns operationStoreList
42
+ every { mockOperationModelStore.add(any()) } answers { operationStoreList.add(firstArg<Operation >()) }
43
+ every { mockOperationModelStore.remove(any()) } answers {
44
+ val id = firstArg<String >()
45
+ val op = operationStoreList.firstOrNull { it.id == id }
46
+ operationStoreList.remove(op)
47
+ }
42
48
mockOperationModelStore
43
49
}
44
50
@@ -117,9 +123,9 @@ class OperationRepoTests : FunSpec({
117
123
test("enqueue operation executes and is removed when executed") {
118
124
// Given
119
125
val mocks = Mocks ()
120
-
121
126
val operationIdSlot = slot<String >()
122
127
val operation = mockOperation(operationIdSlot = operationIdSlot)
128
+ val opId = operation.id
123
129
124
130
// When
125
131
mocks.operationRepo.start()
@@ -136,7 +142,7 @@ class OperationRepoTests : FunSpec({
136
142
it[0] shouldBe operation
137
143
},
138
144
)
139
- mocks.operationModelStore.remove("operationId" )
145
+ mocks.operationModelStore.remove(opId )
140
146
}
141
147
}
142
148
@@ -151,6 +157,7 @@ class OperationRepoTests : FunSpec({
151
157
152
158
val operationIdSlot = slot<String >()
153
159
val operation = mockOperation(operationIdSlot = operationIdSlot)
160
+ val opId = operation.id
154
161
155
162
// When
156
163
opRepo.start()
@@ -174,7 +181,7 @@ class OperationRepoTests : FunSpec({
174
181
it[0] shouldBe operation
175
182
},
176
183
)
177
- mocks.operationModelStore.remove("operationId" )
184
+ mocks.operationModelStore.remove(opId )
178
185
}
179
186
}
180
187
@@ -210,6 +217,7 @@ class OperationRepoTests : FunSpec({
210
217
211
218
val operationIdSlot = slot<String >()
212
219
val operation = mockOperation(operationIdSlot = operationIdSlot)
220
+ val opId = operation.id
213
221
214
222
// When
215
223
mocks.operationRepo.start()
@@ -226,7 +234,7 @@ class OperationRepoTests : FunSpec({
226
234
it[0] shouldBe operation
227
235
},
228
236
)
229
- mocks.operationModelStore.remove("operationId" )
237
+ mocks.operationModelStore.remove(opId )
230
238
}
231
239
}
232
240
@@ -608,10 +616,24 @@ class OperationRepoTests : FunSpec({
608
616
spyListener.onOperationRepoLoaded()
609
617
}
610
618
}
619
+
620
+ test("ensure loadSavedOperations doesn't duplicate existing OperationItems ") {
621
+ // Given
622
+ val mocks = Mocks ()
623
+ val op = mockOperation()
624
+ mocks.operationRepo.enqueue(op)
625
+
626
+ // When
627
+ mocks.operationRepo.loadSavedOperations()
628
+
629
+ // Then
630
+ mocks.operationRepo.queue.size shouldBe 1
631
+ mocks.operationRepo.queue.first().operation shouldBe op
632
+ }
611
633
}) {
612
634
companion object {
613
635
private fun mockOperation (
614
- id : String = "operationId" ,
636
+ id : String = UUID .randomUUID().toString() ,
615
637
name : String = "DUMMY_OPERATION ",
616
638
canStartExecute : Boolean = true,
617
639
groupComparisonType : GroupComparisonType = GroupComparisonType .NONE ,
0 commit comments