chinwag-android/app/src/androidTest/java/com/keylesspalace/tusky/MigrationsTest.kt
Bernd 0db1a23c4f Update Deps + Cleanup (#1158)
* Fix Typo

* Update build.gradle

* Update Deps

* Update Tests

* Fixes Tests

Without this some tests fail on my PC...

+ also:
"Put this in your gradle.properties:

android.enableUnitTestBinaryResources=true"
from http://robolectric.org/migrating/#project-configuration

* Make everything private

* Fix Warning

* Update TimelineFragment.java

* Update build.gradle

* Update gradle-wrapper.properties

* Update gradle-wrapper.properties

* Update gradle-wrapper.properties

* Fix Compile Errors

e.g.

Type inference failed. Expected type mismatch: inferred type is Preference? but Preference was expected

Type inference failed. Please try to specify type arguments explicitly.

* fix crash

* Grandle Wrapper 5.3

* Revert "Fix Compile Errors"

This reverts commit 4a774a4fe3ce82c84bd7b4d78e1a1c64af97cd0d.

* requirePreference

* oops

* Cleanup

* Update gradle-wrapper.properties
2019-03-30 15:18:16 +01:00

64 lines
2.5 KiB
Kotlin

package com.keylesspalace.tusky
import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.keylesspalace.tusky.db.AppDatabase
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
const val TEST_DB = "migration_test"
@RunWith(AndroidJUnit4::class)
class MigrationsTest {
@JvmField
@Rule
var helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
AppDatabase::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
)
@Test
fun migrateTo11() {
val db = helper.createDatabase(TEST_DB, 10)
val id = 1
val domain = "domain.site"
val token = "token"
val active = true
val accountId = "accountId"
val username = "username"
val values = arrayOf(id, domain, token, active, accountId, username, "Display Name",
"https://picture.url", true, true, true, true, true, true, true,
true, "1000", "[]", "[{\"shortcode\": \"emoji\", \"url\": \"yes\"}]", 0, false,
false, true)
db.execSQL("INSERT OR REPLACE INTO `AccountEntity`(`id`,`domain`,`accessToken`,`isActive`," +
"`accountId`,`username`,`displayName`,`profilePictureUrl`,`notificationsEnabled`," +
"`notificationsMentioned`,`notificationsFollowed`,`notificationsReblogged`," +
"`notificationsFavorited`,`notificationSound`,`notificationVibration`," +
"`notificationLight`,`lastNotificationId`,`activeNotifications`,`emojis`," +
"`defaultPostPrivacy`,`defaultMediaSensitivity`,`alwaysShowSensitiveMedia`," +
"`mediaPreviewEnabled`) " +
"VALUES (nullif(?, 0),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
values)
db.close()
val newDb = helper.runMigrationsAndValidate(TEST_DB, 11, true, AppDatabase.MIGRATION_10_11)
val cursor = newDb.query("SELECT * FROM AccountEntity")
cursor.moveToFirst()
assertEquals(id, cursor.getInt(0))
assertEquals(domain, cursor.getString(1))
assertEquals(token, cursor.getString(2))
assertEquals(active, cursor.getInt(3) != 0)
assertEquals(accountId, cursor.getString(4))
assertEquals(username, cursor.getString(5))
}
}