|
|
|
|
@ -6,8 +6,6 @@ import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.koitharu.kotatsu.core.db.migrations.*
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
|
@ -19,10 +17,20 @@ class MangaDatabaseTest {
|
|
|
|
|
MangaDatabase::class.java,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private val migrations = databaseMigrations
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
|
fun migrateAll() {
|
|
|
|
|
fun versions() {
|
|
|
|
|
assertEquals(1, migrations.first().startVersion)
|
|
|
|
|
repeat(migrations.size) { i ->
|
|
|
|
|
assertEquals(i + 1, migrations[i].startVersion)
|
|
|
|
|
assertEquals(i + 2, migrations[i].endVersion)
|
|
|
|
|
}
|
|
|
|
|
assertEquals(DATABASE_VERSION, migrations.last().endVersion)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun migrateAll() {
|
|
|
|
|
helper.createDatabase(TEST_DB, 1).close()
|
|
|
|
|
for (migration in migrations) {
|
|
|
|
|
helper.runMigrationsAndValidate(
|
|
|
|
|
@ -34,22 +42,16 @@ class MangaDatabaseTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun prePopulate() {
|
|
|
|
|
val resources = InstrumentationRegistry.getInstrumentation().targetContext.resources
|
|
|
|
|
helper.createDatabase(TEST_DB, DATABASE_VERSION).use {
|
|
|
|
|
DatabasePrePopulateCallback(resources).onCreate(it)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private companion object {
|
|
|
|
|
|
|
|
|
|
const val TEST_DB = "test-db"
|
|
|
|
|
|
|
|
|
|
val migrations = arrayOf(
|
|
|
|
|
Migration1To2(),
|
|
|
|
|
Migration2To3(),
|
|
|
|
|
Migration3To4(),
|
|
|
|
|
Migration4To5(),
|
|
|
|
|
Migration5To6(),
|
|
|
|
|
Migration6To7(),
|
|
|
|
|
Migration7To8(),
|
|
|
|
|
Migration8To9(),
|
|
|
|
|
Migration9To10(),
|
|
|
|
|
Migration10To11(),
|
|
|
|
|
Migration11To12(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|