From 34bb852bfbc9099d242ba3cd137d7d9c7de125ea Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 25 May 2022 18:41:51 +0200 Subject: [PATCH 1/5] Upgrade to AGP 7.2 --- Corona-Warn-App/build.gradle | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Corona-Warn-App/build.gradle b/Corona-Warn-App/build.gradle index 52c46716a9f..238515773db 100644 --- a/Corona-Warn-App/build.gradle +++ b/Corona-Warn-App/build.gradle @@ -373,7 +373,7 @@ dependencies { implementation "androidx.recyclerview:recyclerview-selection:1.1.0" // DAGGER - def dagger_version = "2.38.1" + def dagger_version = "2.41" implementation "com.google.dagger:dagger:$dagger_version" implementation "com.google.dagger:dagger-android:$dagger_version" implementation "com.google.dagger:dagger-android-support:$dagger_version" diff --git a/build.gradle b/build.gradle index ae19a81d0a0..5654df8d0ec 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'com.android.tools.build:gradle:7.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f68014cbb84..cbfaacc58e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip From 60033ac9f3f5a10e9b4b302f99af59bc0a796074 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Thu, 26 May 2022 12:21:39 +0200 Subject: [PATCH 2/5] Update build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5654df8d0ec..b59140e895c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' + classpath 'com.android.tools.build:gradle:7.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" From 18615f5d4e561a36a5c95c21691d7db5e38c0a47 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Thu, 26 May 2022 14:51:44 +0200 Subject: [PATCH 3/5] Fix source sets --- Corona-Warn-App/build.gradle | 2 -- .../ContactDiaryDatabaseMigrationTest.kt | 3 +-- .../RiskResultDatabaseMigrationTest.kt | 7 +++--- .../coronawarnapp/ui/statistics/Statistics.kt | 2 +- .../testhelpers/BaseTestInstrumentation.kt | 1 - .../androidTest/java/testhelpers/JUnitTree.kt | 22 ++++++++++++++++ .../java/testhelpers/MockFlowPreference.kt | 21 ++++++++++++++++ .../testhelpers/TestDispatcherProvider.kt | 0 .../grouping/DccGroupingExtensionsTest.kt | 4 +-- .../grouping/DccHolderComparisonTest.kt | 3 +-- .../grouping/DccHolderNameComponentsTest.kt | 3 +-- .../java/testhelpers/IsAUnitTest.kt | 0 .../testhelpers/TestDispatcherProvider.kt | 23 +++++++++++++++++ .../java/testhelpers/logging/JUnitTree.kt | 0 .../testhelpers/preferences/FakeDataStore.kt | 0 .../preferences/FakeTypedDataStore.kt | 0 .../preferences/MockFlowPreference.kt | 0 .../preferences/MockSharedPreferences.kt | 0 .../ExposureWindowProviderTest.kt | 3 +-- .../api/ui/TestForApiFragmentViewModelTest.kt | 25 ------------------- .../ui/DebugOptionsFragmentViewModelTest.kt | 3 +-- .../storage/DefaultRiskLevelStorageTest.kt | 3 +-- 22 files changed, 79 insertions(+), 46 deletions(-) rename Corona-Warn-App/src/{testShared => androidTest}/java/testhelpers/BaseTestInstrumentation.kt (93%) create mode 100644 Corona-Warn-App/src/androidTest/java/testhelpers/JUnitTree.kt create mode 100644 Corona-Warn-App/src/androidTest/java/testhelpers/MockFlowPreference.kt rename Corona-Warn-App/src/{testShared => androidTest}/java/testhelpers/TestDispatcherProvider.kt (100%) rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/IsAUnitTest.kt (100%) create mode 100644 Corona-Warn-App/src/test/java/testhelpers/TestDispatcherProvider.kt rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/logging/JUnitTree.kt (100%) rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/preferences/FakeDataStore.kt (100%) rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/preferences/FakeTypedDataStore.kt (100%) rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/preferences/MockFlowPreference.kt (100%) rename Corona-Warn-App/src/{testShared => test}/java/testhelpers/preferences/MockSharedPreferences.kt (100%) delete mode 100644 Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForApiFragmentViewModelTest.kt diff --git a/Corona-Warn-App/build.gradle b/Corona-Warn-App/build.gradle index 238515773db..e73c5cc4a0f 100644 --- a/Corona-Warn-App/build.gradle +++ b/Corona-Warn-App/build.gradle @@ -256,11 +256,9 @@ android { } } test { - java.srcDirs += "$projectDir/src/testShared/java" resources.srcDirs += "src/main/assets" } androidTest { - java.srcDirs += "$projectDir/src/testShared/java" androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } } diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt index 17c6963cbe8..40f30ed8010 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt @@ -37,8 +37,7 @@ class ContactDiaryDatabaseMigrationTest : BaseTestInstrumentation() { @get:Rule val helper: MigrationTestHelper = MigrationTestHelper( InstrumentationRegistry.getInstrumentation(), - ContactDiaryDatabase::class.java.canonicalName, - FrameworkSQLiteOpenHelperFactory() + ContactDiaryDatabase::class.java ) /** diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt index 7535a1c304d..edf48c7ec11 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt @@ -32,8 +32,7 @@ class RiskResultDatabaseMigrationTest : BaseTestInstrumentation() { @get:Rule val helper: MigrationTestHelper = MigrationTestHelper( InstrumentationRegistry.getInstrumentation(), - RiskResultDatabase::class.java.canonicalName, - FrameworkSQLiteOpenHelperFactory() + RiskResultDatabase::class.java ) /** @@ -280,7 +279,9 @@ class RiskResultDatabaseMigrationTest : BaseTestInstrumentation() { riskLevel.id shouldBe riskLevelValues["id"] riskLevel.calculatedAt shouldBe Instant.parse(riskLevelValues["calculatedAt"] as String) riskLevel.aggregatedRiskResult shouldNotBe null - riskLevel.aggregatedRiskResult?.totalRiskLevel shouldBe RiskCalculationParametersOuterClass.NormalizedTimeToRiskLevelMapping.RiskLevel.forNumber(riskLevelValues["totalRiskLevel"] as Int) + riskLevel.aggregatedRiskResult?.totalRiskLevel shouldBe RiskCalculationParametersOuterClass.NormalizedTimeToRiskLevelMapping.RiskLevel.forNumber( + riskLevelValues["totalRiskLevel"] as Int + ) riskLevel.aggregatedRiskResult?.totalMinimumDistinctEncountersWithLowRisk shouldBe riskLevelValues["totalMinimumDistinctEncountersWithLowRisk"] riskLevel.aggregatedRiskResult?.totalMinimumDistinctEncountersWithHighRisk shouldBe riskLevelValues["totalMinimumDistinctEncountersWithHighRisk"] riskLevel.aggregatedRiskResult?.mostRecentDateWithLowRisk shouldBe Instant.parse(riskLevelValues["mostRecentDateWithLowRisk"] as String) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/statistics/Statistics.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/statistics/Statistics.kt index dd53ecabe65..493b537a4f2 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/statistics/Statistics.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/statistics/Statistics.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.runBlocking import okhttp3.Cache import org.joda.time.Instant import retrofit2.converter.gson.GsonConverterFactory -import testhelpers.preferences.mockFlowPreference +import testhelpers.mockFlowPreference import timber.log.Timber object Statistics { diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/BaseTestInstrumentation.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/BaseTestInstrumentation.kt similarity index 93% rename from Corona-Warn-App/src/testShared/java/testhelpers/BaseTestInstrumentation.kt rename to Corona-Warn-App/src/androidTest/java/testhelpers/BaseTestInstrumentation.kt index 3b49868951e..2a289b087ba 100644 --- a/Corona-Warn-App/src/testShared/java/testhelpers/BaseTestInstrumentation.kt +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/BaseTestInstrumentation.kt @@ -2,7 +2,6 @@ package testhelpers import io.mockk.unmockkAll import org.junit.AfterClass -import testhelpers.logging.JUnitTree import timber.log.Timber abstract class BaseTestInstrumentation { diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/JUnitTree.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/JUnitTree.kt new file mode 100644 index 00000000000..ebd37f4d120 --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/JUnitTree.kt @@ -0,0 +1,22 @@ +package testhelpers + +import android.util.Log + +import timber.log.Timber + +class JUnitTree(private val minLogLevel: Int = Log.VERBOSE) : Timber.DebugTree() { + + private fun priorityToString(priority: Int): String = when (priority) { + Log.ERROR -> "E" + Log.WARN -> "W" + Log.INFO -> "I" + Log.DEBUG -> "D" + Log.VERBOSE -> "V" + else -> priority.toString() + } + + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + if (priority < minLogLevel) return + println("${System.currentTimeMillis()} ${priorityToString(priority)}/$tag: $message") + } +} diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/MockFlowPreference.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/MockFlowPreference.kt new file mode 100644 index 00000000000..115314ada4c --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/MockFlowPreference.kt @@ -0,0 +1,21 @@ +package testhelpers + +import de.rki.coronawarnapp.util.preferences.FlowPreference +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.flow.MutableStateFlow + +fun mockFlowPreference( + defaultValue: T +): FlowPreference { + val instance = mockk>() + val flow = MutableStateFlow(defaultValue) + every { instance.flow } answers { flow } + every { instance.value } answers { flow.value } + every { instance.update(any()) } answers { + val updateCall = arg<(T) -> T>(0) + flow.value = updateCall(flow.value) + } + + return instance +} diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/TestDispatcherProvider.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/TestDispatcherProvider.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/TestDispatcherProvider.kt rename to Corona-Warn-App/src/androidTest/java/testhelpers/TestDispatcherProvider.kt diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt index a40d55695fe..42639161c80 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt @@ -8,9 +8,9 @@ import io.kotest.matchers.shouldBe import io.mockk.every import io.mockk.mockk import org.junit.jupiter.api.Test -import testhelpers.BaseTestInstrumentation -class DccGroupingExtensionsTest : BaseTestInstrumentation() { + +class DccGroupingExtensionsTest : testhelpers.BaseTest() { @Test fun `first grouping check`() { diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderComparisonTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderComparisonTest.kt index 23270db79fa..88af032e6d8 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderComparisonTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderComparisonTest.kt @@ -7,9 +7,8 @@ import io.mockk.every import io.mockk.mockk import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource -import testhelpers.BaseTestInstrumentation -class DccHolderComparisonTest : BaseTestInstrumentation() { +class DccHolderComparisonTest : testhelpers.BaseTest() { @ParameterizedTest(name = "{index}: {0}") @ArgumentsSource(DccHolderComparisonTestCaseProvider::class) diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderNameComponentsTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderNameComponentsTest.kt index 1fe200442ec..fda3f7d4cf7 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderNameComponentsTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccHolderNameComponentsTest.kt @@ -5,9 +5,8 @@ import de.rki.coronawarnapp.covidcertificate.common.certificate.CertificatePerso import io.kotest.matchers.shouldBe import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource -import testhelpers.BaseTestInstrumentation -class DccHolderNameComponentsTest : BaseTestInstrumentation() { +class DccHolderNameComponentsTest : testhelpers.BaseTest() { @ParameterizedTest(name = "{index}: {0}") @ArgumentsSource(DccHolderNameComponentsTestCaseProvider::class) diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/IsAUnitTest.kt b/Corona-Warn-App/src/test/java/testhelpers/IsAUnitTest.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/IsAUnitTest.kt rename to Corona-Warn-App/src/test/java/testhelpers/IsAUnitTest.kt diff --git a/Corona-Warn-App/src/test/java/testhelpers/TestDispatcherProvider.kt b/Corona-Warn-App/src/test/java/testhelpers/TestDispatcherProvider.kt new file mode 100644 index 00000000000..9aff497b970 --- /dev/null +++ b/Corona-Warn-App/src/test/java/testhelpers/TestDispatcherProvider.kt @@ -0,0 +1,23 @@ +package testhelpers + +import de.rki.coronawarnapp.util.coroutine.DispatcherProvider +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlin.coroutines.CoroutineContext + +class TestDispatcherProvider(private val context: CoroutineContext? = null) : DispatcherProvider { + override val Default: CoroutineContext + get() = context ?: Dispatchers.Unconfined + override val Main: CoroutineContext + get() = context ?: Dispatchers.Unconfined + override val MainImmediate: CoroutineContext + get() = context ?: Dispatchers.Unconfined + override val Unconfined: CoroutineContext + get() = context ?: Dispatchers.Unconfined + override val IO: CoroutineContext + get() = context ?: Dispatchers.Unconfined +} + +fun CoroutineScope.asDispatcherProvider() = this.coroutineContext.asDispatcherProvider() + +fun CoroutineContext.asDispatcherProvider() = TestDispatcherProvider(context = this) diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/logging/JUnitTree.kt b/Corona-Warn-App/src/test/java/testhelpers/logging/JUnitTree.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/logging/JUnitTree.kt rename to Corona-Warn-App/src/test/java/testhelpers/logging/JUnitTree.kt diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/preferences/FakeDataStore.kt b/Corona-Warn-App/src/test/java/testhelpers/preferences/FakeDataStore.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/preferences/FakeDataStore.kt rename to Corona-Warn-App/src/test/java/testhelpers/preferences/FakeDataStore.kt diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/preferences/FakeTypedDataStore.kt b/Corona-Warn-App/src/test/java/testhelpers/preferences/FakeTypedDataStore.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/preferences/FakeTypedDataStore.kt rename to Corona-Warn-App/src/test/java/testhelpers/preferences/FakeTypedDataStore.kt diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/preferences/MockFlowPreference.kt b/Corona-Warn-App/src/test/java/testhelpers/preferences/MockFlowPreference.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/preferences/MockFlowPreference.kt rename to Corona-Warn-App/src/test/java/testhelpers/preferences/MockFlowPreference.kt diff --git a/Corona-Warn-App/src/testShared/java/testhelpers/preferences/MockSharedPreferences.kt b/Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt similarity index 100% rename from Corona-Warn-App/src/testShared/java/testhelpers/preferences/MockSharedPreferences.kt rename to Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt diff --git a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/nearby/modules/exposurewindow/ExposureWindowProviderTest.kt b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/nearby/modules/exposurewindow/ExposureWindowProviderTest.kt index 00acd3ba984..bf383a1197b 100644 --- a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/nearby/modules/exposurewindow/ExposureWindowProviderTest.kt +++ b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/nearby/modules/exposurewindow/ExposureWindowProviderTest.kt @@ -9,10 +9,9 @@ import io.mockk.coEvery import io.mockk.impl.annotations.MockK import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import testhelpers.BaseTestInstrumentation import testhelpers.gms.MockGMSTask -class ExposureWindowProviderTest : BaseTestInstrumentation() { +class ExposureWindowProviderTest : testhelpers.BaseTest() { @MockK lateinit var googleENFClient: ExposureNotificationClient @MockK lateinit var testSettings: TestSettings @MockK lateinit var fakeExposureWindowProvider: FakeExposureWindowProvider diff --git a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForApiFragmentViewModelTest.kt b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForApiFragmentViewModelTest.kt deleted file mode 100644 index ac7eb09e861..00000000000 --- a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForApiFragmentViewModelTest.kt +++ /dev/null @@ -1,25 +0,0 @@ -package de.rki.coronawarnapp.test.api.ui - -import android.content.Context -import de.rki.coronawarnapp.environment.EnvironmentSetup -import de.rki.coronawarnapp.task.TaskController -import io.mockk.MockKAnnotations -import io.mockk.impl.annotations.MockK -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.extension.ExtendWith -import testhelpers.BaseTestInstrumentation -import testhelpers.extensions.InstantExecutorExtension - -@ExtendWith(InstantExecutorExtension::class) -class TestForApiFragmentViewModelTest : BaseTestInstrumentation() { - - @MockK private lateinit var context: Context - @MockK lateinit var taskController: TaskController - - private var currentEnvironment = EnvironmentSetup.Type.DEV - - @BeforeEach - fun setup() { - MockKAnnotations.init(this) - } -} diff --git a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/debugoptions/ui/DebugOptionsFragmentViewModelTest.kt b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/debugoptions/ui/DebugOptionsFragmentViewModelTest.kt index c128d597d10..5159c7ebe0e 100644 --- a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/debugoptions/ui/DebugOptionsFragmentViewModelTest.kt +++ b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/debugoptions/ui/DebugOptionsFragmentViewModelTest.kt @@ -9,13 +9,12 @@ import io.mockk.impl.annotations.MockK import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import testhelpers.BaseTestInstrumentation import testhelpers.TestDispatcherProvider import testhelpers.extensions.InstantExecutorExtension import testhelpers.extensions.getOrAwaitValue @ExtendWith(InstantExecutorExtension::class) -class DebugOptionsFragmentViewModelTest : BaseTestInstrumentation() { +class DebugOptionsFragmentViewModelTest : testhelpers.BaseTest() { @MockK private lateinit var environmentSetup: EnvironmentSetup @MockK private lateinit var dscRepository: DscRepository diff --git a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/risk/storage/DefaultRiskLevelStorageTest.kt b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/risk/storage/DefaultRiskLevelStorageTest.kt index 06ea475e50c..dc202ebb947 100644 --- a/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/risk/storage/DefaultRiskLevelStorageTest.kt +++ b/Corona-Warn-App/src/testDeviceForTesters/java/de/rki/coronawarnapp/test/risk/storage/DefaultRiskLevelStorageTest.kt @@ -25,9 +25,8 @@ import kotlinx.coroutines.test.runTest import org.joda.time.Instant import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import testhelpers.BaseTestInstrumentation -class DefaultRiskLevelStorageTest : BaseTestInstrumentation() { +class DefaultRiskLevelStorageTest : testhelpers.BaseTest() { @MockK lateinit var databaseFactory: RiskResultDatabase.Factory @MockK lateinit var database: RiskResultDatabase From 625332af95ca1caa88b64b58dea3635ccf0d1652 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Fri, 27 May 2022 10:34:26 +0200 Subject: [PATCH 4/5] Lint --- .../storage/ContactDiaryDatabaseMigrationTest.kt | 1 - .../risk/storage/RiskResultDatabaseMigrationTest.kt | 1 - .../ccl/holder/grouping/DccGroupingExtensionsTest.kt | 1 - .../java/testhelpers/preferences/MockSharedPreferences.kt | 8 ++++++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt index 40f30ed8010..9c747cca6e0 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt @@ -4,7 +4,6 @@ import android.content.ContentValues import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteException import androidx.room.testing.MigrationTestHelper -import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt index edf48c7ec11..e64e06cf774 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt @@ -3,7 +3,6 @@ package de.rki.coronawarnapp.risk.storage import android.content.ContentValues import android.database.sqlite.SQLiteDatabase import androidx.room.testing.MigrationTestHelper -import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt index 42639161c80..ec7fc5ce617 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/holder/grouping/DccGroupingExtensionsTest.kt @@ -9,7 +9,6 @@ import io.mockk.every import io.mockk.mockk import org.junit.jupiter.api.Test - class DccGroupingExtensionsTest : testhelpers.BaseTest() { @Test diff --git a/Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt b/Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt index c094e560e54..b928a3bd266 100644 --- a/Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt +++ b/Corona-Warn-App/src/test/java/testhelpers/preferences/MockSharedPreferences.kt @@ -37,11 +37,15 @@ class MockSharedPreferences : SharedPreferences { dataMap.putAll(newData) } - override fun registerOnSharedPreferenceChangeListener(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + override fun registerOnSharedPreferenceChangeListener( + listener: SharedPreferences.OnSharedPreferenceChangeListener + ) { listeners.add(listener) } - override fun unregisterOnSharedPreferenceChangeListener(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + override fun unregisterOnSharedPreferenceChangeListener( + listener: SharedPreferences.OnSharedPreferenceChangeListener + ) { listeners.remove(listener) } From b74de9d80f0c2624d8edca378170db4d698070f4 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Fri, 27 May 2022 11:53:46 +0200 Subject: [PATCH 5/5] Fix tests --- .../ContactDiaryDatabaseMigrationTest.kt | 20 +++++++++++++++++++ .../RiskResultDatabaseMigrationTest.kt | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt index 9c747cca6e0..256f564114d 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/contactdiary/storage/ContactDiaryDatabaseMigrationTest.kt @@ -7,6 +7,7 @@ import androidx.room.testing.MigrationTestHelper import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import de.rki.coronawarnapp.CoronaWarnApplication import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationEntity import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationVisitEntity import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationVisitWrapper @@ -16,13 +17,19 @@ import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryPersonEntity import de.rki.coronawarnapp.contactdiary.storage.internal.migrations.ContactDiaryDatabaseMigration1To2 import de.rki.coronawarnapp.contactdiary.storage.internal.migrations.ContactDiaryDatabaseMigration2To3 import de.rki.coronawarnapp.contactdiary.storage.internal.migrations.ContactDiaryDatabaseMigration3To4 +import de.rki.coronawarnapp.util.di.AppInjector +import de.rki.coronawarnapp.util.di.ApplicationComponent import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import okio.ByteString.Companion.decodeBase64 import org.joda.time.Duration import org.joda.time.LocalDate +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -39,6 +46,19 @@ class ContactDiaryDatabaseMigrationTest : BaseTestInstrumentation() { ContactDiaryDatabase::class.java ) + @Before + fun setup() { + mockkObject(CoronaWarnApplication) + mockkObject(AppInjector) + every { AppInjector.component } returns mockk(relaxed = true) + .apply { + every { bugReporter } returns mockk( + relaxed = true + ) + } + every { CoronaWarnApplication.getAppContext() } returns ApplicationProvider.getApplicationContext() + } + /** * Test migration to add new optional attributes */ diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt index e64e06cf774..80fd67e57b1 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/risk/storage/RiskResultDatabaseMigrationTest.kt @@ -6,17 +6,24 @@ import androidx.room.testing.MigrationTestHelper import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import de.rki.coronawarnapp.CoronaWarnApplication import de.rki.coronawarnapp.risk.EwRiskLevelResult import de.rki.coronawarnapp.risk.storage.internal.RiskResultDatabase import de.rki.coronawarnapp.risk.storage.internal.migrations.RiskResultDatabaseMigration1To2 import de.rki.coronawarnapp.risk.storage.internal.migrations.RiskResultDatabaseMigration2To3 import de.rki.coronawarnapp.risk.storage.internal.riskresults.PersistedRiskLevelResultDao import de.rki.coronawarnapp.server.protocols.internal.v2.RiskCalculationParametersOuterClass +import de.rki.coronawarnapp.util.di.AppInjector +import de.rki.coronawarnapp.util.di.ApplicationComponent import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import org.joda.time.Instant +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -34,6 +41,19 @@ class RiskResultDatabaseMigrationTest : BaseTestInstrumentation() { RiskResultDatabase::class.java ) + @Before + fun setup() { + mockkObject(CoronaWarnApplication) + mockkObject(AppInjector) + every { AppInjector.component } returns mockk(relaxed = true) + .apply { + every { bugReporter } returns mockk( + relaxed = true + ) + } + every { CoronaWarnApplication.getAppContext() } returns ApplicationProvider.getApplicationContext() + } + /** * Test migration to create new primary key "monotonicId" column */