File tree Expand file tree Collapse file tree 2 files changed +28
-40
lines changed
collect_app/src/test/java/org/odk/collect/android/database
db/src/test/java/org/odk/collect/db/sqlite Expand file tree Collapse file tree 2 files changed +28
-40
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,11 +3,14 @@ package org.odk.collect.db.sqlite
33import android.content.Context
44import androidx.test.core.app.ApplicationProvider
55import androidx.test.ext.junit.runners.AndroidJUnit4
6+ import org.junit.Assert.assertFalse
7+ import org.junit.Assert.assertTrue
68import org.junit.Assert.fail
79import org.junit.Test
810import org.junit.runner.RunWith
911import org.odk.collect.db.sqlite.support.NoopMigrator
1012import org.odk.collect.shared.TempFiles
13+ import java.io.File
1114
1215@RunWith(AndroidJUnit4 ::class )
1316class 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}
You can’t perform that action at this time.
0 commit comments