Skip to content

Commit 453e032

Browse files
committed
Combine tests
1 parent 4aac203 commit 453e032

File tree

2 files changed

+28
-40
lines changed

2 files changed

+28
-40
lines changed

collect_app/src/test/java/org/odk/collect/android/database/DatabaseConnectionTest.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

db/src/test/java/org/odk/collect/db/sqlite/DatabaseConnectionTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package org.odk.collect.db.sqlite
33
import android.content.Context
44
import androidx.test.core.app.ApplicationProvider
55
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import org.junit.Assert.assertFalse
7+
import org.junit.Assert.assertTrue
68
import org.junit.Assert.fail
79
import org.junit.Test
810
import org.junit.runner.RunWith
911
import org.odk.collect.db.sqlite.support.NoopMigrator
1012
import org.odk.collect.shared.TempFiles
13+
import java.io.File
1114

1215
@RunWith(AndroidJUnit4::class)
1316
class DatabaseConnectionTest {
@@ -44,4 +47,29 @@ class DatabaseConnectionTest {
4447
// Expected
4548
}
4649
}
50+
51+
// https://github.com/getodk/collect/issues/5042
52+
@Test
53+
fun `database file should be recreated if removed between operations`() {
54+
val dbDir = TempFiles.createTempDir()
55+
val dbFileName = "temp.db"
56+
val dbPath = dbDir.absolutePath + File.separator + dbFileName
57+
58+
DatabaseConnection(
59+
context,
60+
dbDir.absolutePath,
61+
dbFileName,
62+
NoopMigrator(),
63+
1
64+
).also {
65+
it.readableDatabase
66+
assertTrue(File(dbPath).exists())
67+
68+
File(dbPath).delete()
69+
assertFalse(File(dbPath).exists())
70+
71+
it.readableDatabase
72+
assertTrue(File(dbPath).exists())
73+
}
74+
}
4775
}

0 commit comments

Comments
 (0)