pull/1251/head
parent
5ad9a8413b
commit
b33dcb8200
@ -0,0 +1,50 @@ |
||||
package io.legado.app |
||||
|
||||
import androidx.room.Room |
||||
import androidx.room.migration.Migration |
||||
import androidx.room.testing.MigrationTestHelper |
||||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory |
||||
import androidx.test.platform.app.InstrumentationRegistry |
||||
import androidx.test.runner.AndroidJUnit4 |
||||
import io.legado.app.data.AppDatabase |
||||
import org.junit.Rule |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import java.io.IOException |
||||
|
||||
@RunWith(AndroidJUnit4::class) |
||||
class MigrationTest { |
||||
private val TEST_DB = "migration-test" |
||||
|
||||
private val ALL_MIGRATIONS = arrayOf<Migration>( |
||||
|
||||
) |
||||
|
||||
@Rule |
||||
val helper: MigrationTestHelper = MigrationTestHelper( |
||||
InstrumentationRegistry.getInstrumentation(), |
||||
AppDatabase::class.java.canonicalName, |
||||
FrameworkSQLiteOpenHelperFactory() |
||||
) |
||||
|
||||
@Test |
||||
@Throws(IOException::class) |
||||
fun migrateAll() { |
||||
// Create earliest version of the database. |
||||
helper.createDatabase(TEST_DB, 30).apply { |
||||
close() |
||||
} |
||||
|
||||
// Open latest version of the database. Room will validate the schema |
||||
// once all migrations execute. |
||||
Room.databaseBuilder( |
||||
InstrumentationRegistry.getInstrumentation().targetContext, |
||||
AppDatabase::class.java, |
||||
TEST_DB |
||||
).addMigrations(*ALL_MIGRATIONS) |
||||
.build().apply { |
||||
openHelper.writableDatabase |
||||
close() |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@color/background" |
||||
android:gravity="center" |
||||
android:padding="20dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/title" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingBottom="12dp" |
||||
android:textSize="16sp" |
||||
android:textStyle="bold" |
||||
android:text="@string/login" /> |
||||
|
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue