Remove tests deprecations (#2260)

This commit is contained in:
Mikołaj Pich 2023-07-25 11:37:43 +02:00 committed by GitHub
parent e79c5d4d2b
commit 5b2e2ffb34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 32 deletions

View File

@ -2,7 +2,6 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization' apply plugin: 'kotlinx-serialization'
apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.devtools.ksp' apply plugin: 'com.google.devtools.ksp'
apply plugin: 'dagger.hilt.android.plugin' apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
@ -11,6 +10,7 @@ apply plugin: 'com.github.triplet.play'
apply plugin: 'ru.cian.huawei-publish' apply plugin: 'ru.cian.huawei-publish'
apply plugin: 'com.mikepenz.aboutlibraries.plugin' apply plugin: 'com.mikepenz.aboutlibraries.plugin'
apply plugin: 'com.huawei.agconnect' apply plugin: 'com.huawei.agconnect'
apply plugin: 'kotlin-kapt'
apply from: 'jacoco.gradle' apply from: 'jacoco.gradle'
apply from: 'sonarqube.gradle' apply from: 'sonarqube.gradle'
apply from: 'hooks.gradle' apply from: 'hooks.gradle'

View File

@ -2,7 +2,8 @@ package io.github.wulkanowy
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain import kotlinx.coroutines.test.setMain
import org.junit.rules.TestWatcher import org.junit.rules.TestWatcher
@ -10,17 +11,14 @@ import org.junit.runner.Description
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
class MainCoroutineRule( class MainCoroutineRule(
private val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()
) : TestWatcher() { ) : TestWatcher() {
override fun starting(description: Description?) { override fun starting(description: Description) {
super.starting(description)
Dispatchers.setMain(testDispatcher) Dispatchers.setMain(testDispatcher)
} }
override fun finished(description: Description?) { override fun finished(description: Description) {
super.finished(description)
Dispatchers.resetMain() Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
} }
} }

View File

@ -22,7 +22,8 @@ abstract class AbstractMigrationTest {
@get:Rule @get:Rule
val helper: MigrationTestHelper = MigrationTestHelper( val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(), InstrumentationRegistry.getInstrumentation(),
AppDatabase::class.java.canonicalName, AppDatabase::class.java,
listOf(Migration55()),
FrameworkSQLiteOpenHelperFactory() FrameworkSQLiteOpenHelperFactory()
) )

View File

@ -22,12 +22,12 @@ class Migration12Test : AbstractMigrationTest() {
fun twoNotRelatedStudents() { fun twoNotRelatedStudents() {
helper.createDatabase(dbName, 11).apply { helper.createDatabase(dbName, 11).apply {
// user 1 // user 1
createStudent(this, 1, true) createStudent(this, 1)
createSemester(this, 1, false, 5, 1) createSemester(this, 1, false, 5, 1)
createSemester(this, 1, true, 5, 2) createSemester(this, 1, true, 5, 2)
// user 2 // user 2
createStudent(this, 2, true) createStudent(this, 2)
createSemester(this, 2, false, 6, 1) createSemester(this, 2, false, 6, 1)
createSemester(this, 2, true, 6, 2) createSemester(this, 2, true, 6, 2)
close() close()
@ -56,9 +56,9 @@ class Migration12Test : AbstractMigrationTest() {
fun removeStudentsWithoutClassId() { fun removeStudentsWithoutClassId() {
helper.createDatabase(dbName, 11).apply { helper.createDatabase(dbName, 11).apply {
// user 1 // user 1
createStudent(this, 1, true) createStudent(this, 1)
createSemester(this, 1, false, 0, 2) createSemester(this, 1, false, 0, 2)
createStudent(this, 2, true) createStudent(this, 2)
createSemester(this, 2, true, 1, 2) createSemester(this, 2, true, 1, 2)
close() close()
} }
@ -81,11 +81,11 @@ class Migration12Test : AbstractMigrationTest() {
fun ensureThereIsOnlyOneCurrentStudent() { fun ensureThereIsOnlyOneCurrentStudent() {
helper.createDatabase(dbName, 11).apply { helper.createDatabase(dbName, 11).apply {
// user 1 // user 1
createStudent(this, 1, true) createStudent(this, 1)
createSemester(this, 1, true, 5, 2) createSemester(this, 1, true, 5, 2)
createStudent(this, 2, true) createStudent(this, 2)
createSemester(this, 2, true, 6, 2) createSemester(this, 2, true, 6, 2)
createStudent(this, 3, true) createStudent(this, 3)
createSemester(this, 3, false, 7, 2) createSemester(this, 3, false, 7, 2)
close() close()
} }
@ -112,7 +112,7 @@ class Migration12Test : AbstractMigrationTest() {
db.close() db.close()
} }
private fun createStudent(db: SupportSQLiteDatabase, studentId: Int, isCurrent: Boolean) { private fun createStudent(db: SupportSQLiteDatabase, studentId: Int) {
db.insert("Students", CONFLICT_FAIL, ContentValues().apply { db.insert("Students", CONFLICT_FAIL, ContentValues().apply {
put("endpoint", "https://fakelog.cf") put("endpoint", "https://fakelog.cf")
put("loginType", "STANDARD") put("loginType", "STANDARD")
@ -123,7 +123,7 @@ class Migration12Test : AbstractMigrationTest() {
put("student_name", "Jan Kowalski") put("student_name", "Jan Kowalski")
put("school_id", "000123") put("school_id", "000123")
put("school_name", "") put("school_name", "")
put("is_current", isCurrent) put("is_current", true)
put("registration_date", "0") put("registration_date", "0")
}) })
} }

View File

@ -95,22 +95,22 @@ class Migration13Test : AbstractMigrationTest() {
fun markAtLeastAndOnlyOneSemesterAtCurrent() { fun markAtLeastAndOnlyOneSemesterAtCurrent() {
helper.createDatabase(dbName, 12).apply { helper.createDatabase(dbName, 12).apply {
createStudent(this, 1, "", 5) createStudent(this, 1, "", 5)
createSemester(this, 1, 5, 1, 1, false) createSemester(this, 1, 1, 1, false)
createSemester(this, 1, 5, 2, 1, false) createSemester(this, 1, 2, 1, false)
createSemester(this, 1, 5, 3, 2, false) createSemester(this, 1, 3, 2, false)
createSemester(this, 1, 5, 4, 2, false) createSemester(this, 1, 4, 2, false)
createStudent(this, 2, "", 5) createStudent(this, 2, "", 5)
createSemester(this, 2, 5, 5, 5, true) createSemester(this, 2, 5, 5, true)
createSemester(this, 2, 5, 6, 5, true) createSemester(this, 2, 6, 5, true)
createSemester(this, 2, 5, 7, 55, true) createSemester(this, 2, 7, 55, true)
createSemester(this, 2, 5, 8, 55, true) createSemester(this, 2, 8, 55, true)
createStudent(this, 3, "", 5) createStudent(this, 3, "", 5)
createSemester(this, 3, 5, 11, 99, false) createSemester(this, 3, 11, 99, false)
createSemester(this, 3, 5, 12, 99, false) createSemester(this, 3, 12, 99, false)
createSemester(this, 3, 5, 13, 100, false) createSemester(this, 3, 13, 100, false)
createSemester(this, 3, 5, 14, 100, true) createSemester(this, 3, 14, 100, true)
close() close()
} }
@ -198,7 +198,13 @@ class Migration13Test : AbstractMigrationTest() {
}) })
} }
private fun createSemester(db: SupportSQLiteDatabase, studentId: Int, classId: Int, semesterId: Int, diaryId: Int, isCurrent: Boolean = false) { private fun createSemester(
db: SupportSQLiteDatabase,
studentId: Int,
semesterId: Int,
diaryId: Int,
isCurrent: Boolean = false
) {
db.insert("Semesters", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply { db.insert("Semesters", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply {
put("student_id", studentId) put("student_id", studentId)
put("diary_id", diaryId) put("diary_id", diaryId)
@ -206,7 +212,7 @@ class Migration13Test : AbstractMigrationTest() {
put("semester_id", semesterId) put("semester_id", semesterId)
put("semester_name", "1") put("semester_name", "1")
put("is_current", isCurrent) put("is_current", isCurrent)
put("class_id", classId) put("class_id", 5)
put("unit_id", "99") put("unit_id", "99")
}) })
} }