-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arnau Mora Gras <[email protected]>
- Loading branch information
1 parent
a77733b
commit ec3bd54
Showing
4 changed files
with
239 additions
and
8 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
app/src/androidTest/java/at/bitfire/icsdroid/BackupTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package at.bitfire.icsdroid | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import at.bitfire.icsdroid.db.AppDatabase | ||
import at.bitfire.icsdroid.db.entity.Subscription | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class BackupTest { | ||
companion object { | ||
val appContext: Context by lazy { InstrumentationRegistry.getInstrumentation().targetContext } | ||
|
||
private val subscription1 = | ||
Subscription(1, null, Uri.parse("https://example.com/calendar1.ics"), null, "Example 1") | ||
private val subscription2 = | ||
Subscription(2, null, Uri.parse("https://example.com/calendar2.ics"), null, "Example 2") | ||
} | ||
|
||
@Before | ||
fun prepare_database() { | ||
// Change the database name | ||
AppDatabase.databaseName = "icsx5-test" | ||
|
||
// Create the database, and add some sample subscriptions | ||
val database = AppDatabase.getInstance(appContext) | ||
|
||
val subscriptionsDao = database.subscriptionsDao() | ||
subscriptionsDao.add(subscription1) | ||
subscriptionsDao.add(subscription2) | ||
} | ||
|
||
@Test | ||
fun test_import_export() { | ||
// Get the data stored in the db | ||
// Note: This closes the database | ||
val data = runBlocking { AppDatabase.readAllData(appContext) } | ||
|
||
// Clear the data to make sure the test is not confused | ||
AppDatabase.getInstance(appContext).clearAllTables() | ||
|
||
// Import the data | ||
runBlocking { AppDatabase.recreateFromFile(appContext) { data.inputStream() } } | ||
|
||
// Assert | ||
val subscriptionsDao = AppDatabase.getInstance(appContext).subscriptionsDao() | ||
val subscriptions = subscriptionsDao.getAll() | ||
assertEquals(2, subscriptions.size) | ||
assertEquals(subscription1, subscriptions[0]) | ||
assertEquals(subscription2, subscriptions[1]) | ||
} | ||
|
||
@After | ||
fun dispose_database() { | ||
AppDatabase.getInstance(appContext).clearAllTables() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters