forked from ankidroid/Anki-Android
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorageDecisionGateTest.kt
More file actions
41 lines (37 loc) · 1.63 KB
/
Copy pathStorageDecisionGateTest.kt
File metadata and controls
41 lines (37 loc) · 1.63 KB
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
// SPDX-License-Identifier: GPL-3.0-or-later
package com.ichi2.anki
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.exception.StorageNotConfiguredException
import com.ichi2.anki.storage.StorageDecision
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
/**
* Proves the storage-decision gate in [CollectionManager.ensureOpenInner] is wired up. In production
* [CollectionHelper.storageDecision] always returns [com.ichi2.anki.storage.StorageDecision.Decided], so this never fires;
* here we force [com.ichi2.anki.storage.StorageDecision.Undecided] via the test override.
*/
@RunWith(AndroidJUnit4::class)
class StorageDecisionGateTest : RobolectricTest() {
@Test
fun `opening the collection throws when storage is undecided`() {
CollectionHelper.storageDecisionTestOverride = StorageDecision.Undecided
try {
assertFailsWith<StorageNotConfiguredException> { CollectionManager.getColUnsafe() }
} finally {
CollectionHelper.storageDecisionTestOverride = null
}
}
/** No collection access should be attempted: a crash report would otherwise be generated */
@Test
fun `startup failure is StorageUndecided when storage is undecided`() {
CollectionHelper.storageDecisionTestOverride = StorageDecision.Undecided
try {
val failure = InitialActivity.getStartupFailureType { true }
assertEquals(InitialActivity.StartupFailure.StorageUndecided, failure)
} finally {
CollectionHelper.storageDecisionTestOverride = null
}
}
}