- Remove empty file `ExampleInstrumentedTest.java`. - Replace deprecated `MigrationTestHelper` constructor call. - Add reified inline extension methods for `Bundle` and `Intent` to retrieve `Parcelable` and `Serializable` objects by calling the core `BundleCompat` and `IntentCompat` methods, to allow shorter syntax and removing the need to pass the class explicitly. - Replace deprecated `drawable.setColorFilter()` with simpler `drawable.setTint()` (uses blend mode `SRC_IN` by default, has the same effect as `SRC_ATOP` when the source is a color). - Rename shadowed variables (mostly caught exceptions). - Remove unnecessary `.orEmpty()` on non-null fields. - Replace `.size() == 0` with `.isEmpty()`. - Prevent `NullPointerException` when `account.getDisplayName()` is `null` in `StatusBaseViewHolder.setDisplayName()`. - Declare `customEmojis` argument as non-null in `StatusBaseViewHolder.setDisplayName()` because it calls `CustomEmojiHelper.emojify()` which now requires it to be non-null. - Prevent `NullPointerException` when no matching filter is found in `StatusBaseViewHolder.setupFilterPlaceholder()`. - Remove deprecated call to `setTargetFragment()` (target fragment is not used anyway). - Remove deprecated call to `isUserVisibleHint()` and test if the view has been destroyed instead. - Remove some unused imports. - Remove unnecessary casts. - Rename arguments to supertype names when a warning is shown. - Prevent a potential memory leak by clearing the `toolbarVisibilityDisposable` reference in `onDestroyView()`.
66 lines
2.4 KiB
Kotlin
66 lines
2.4 KiB
Kotlin
package com.keylesspalace.tusky
|
|
|
|
import androidx.room.testing.MigrationTestHelper
|
|
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
|
|
)
|
|
|
|
@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))
|
|
}
|
|
}
|