From ccd7873676c7283748331af6019bf9729e0481c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Thu, 18 Jan 2024 18:01:47 +0100 Subject: [PATCH] Move tests to app level as they are not working in a library module --- app-k9mail/build.gradle.kts | 6 +++++ .../app/k9mail}/DependencyInjectionTest.kt | 4 +-- .../unread/UnreadWidgetDataProviderTest.kt | 7 +++--- .../src/test/java/com/fsck/k9/TestApp.kt | 25 ------------------- 4 files changed, 10 insertions(+), 32 deletions(-) rename {app/common/src/test/java/com/fsck/k9 => app-k9mail/src/test/kotlin/app/k9mail}/DependencyInjectionTest.kt (96%) rename {app/common/src/test/java/com/fsck/k9/widget => app-k9mail/src/test/kotlin/app/k9mail}/unread/UnreadWidgetDataProviderTest.kt (97%) delete mode 100644 app/common/src/test/java/com/fsck/k9/TestApp.kt diff --git a/app-k9mail/build.gradle.kts b/app-k9mail/build.gradle.kts index ecd9f32e6..7b98e3073 100644 --- a/app-k9mail/build.gradle.kts +++ b/app-k9mail/build.gradle.kts @@ -19,6 +19,12 @@ dependencies { debugImplementation(projects.backend.demo) implementation(libs.androidx.work.runtime) + + testImplementation(libs.robolectric) + + // Required for DependencyInjectionTest to be able to resolve OpenPgpApiManager + testImplementation(projects.plugins.openpgpApiLib.openpgpApi) + testImplementation(projects.feature.account.setup) } android { diff --git a/app/common/src/test/java/com/fsck/k9/DependencyInjectionTest.kt b/app-k9mail/src/test/kotlin/app/k9mail/DependencyInjectionTest.kt similarity index 96% rename from app/common/src/test/java/com/fsck/k9/DependencyInjectionTest.kt rename to app-k9mail/src/test/kotlin/app/k9mail/DependencyInjectionTest.kt index a96e0badb..64453312b 100644 --- a/app/common/src/test/java/com/fsck/k9/DependencyInjectionTest.kt +++ b/app-k9mail/src/test/kotlin/app/k9mail/DependencyInjectionTest.kt @@ -1,4 +1,4 @@ -package com.fsck.k9 +package app.k9mail import android.view.ContextThemeWrapper import androidx.lifecycle.LifecycleOwner @@ -29,10 +29,8 @@ import org.mockito.kotlin.mock import org.openintents.openpgp.OpenPgpApiManager import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment -import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) -@Config(application = TestApp::class) class DependencyInjectionTest : AutoCloseKoinTest() { private val lifecycleOwner = mock { on { lifecycle } doReturn mock() diff --git a/app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt b/app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt similarity index 97% rename from app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt rename to app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt index 12a022849..001f6717d 100644 --- a/app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt +++ b/app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt @@ -1,4 +1,4 @@ -package com.fsck.k9.widget.unread +package app.k9mail.unread import android.content.Context import assertk.assertThat @@ -6,7 +6,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNull import com.fsck.k9.Account import com.fsck.k9.Preferences -import com.fsck.k9.TestApp import com.fsck.k9.controller.MessageCounts import com.fsck.k9.controller.MessageCountsProvider import com.fsck.k9.mailstore.Folder @@ -15,6 +14,8 @@ import com.fsck.k9.mailstore.FolderType import com.fsck.k9.search.SearchAccount import com.fsck.k9.ui.folders.FolderNameFormatter import com.fsck.k9.ui.messagelist.DefaultFolderProvider +import com.fsck.k9.widget.unread.UnreadWidgetConfiguration +import com.fsck.k9.widget.unread.UnreadWidgetDataProvider import org.junit.Test import org.junit.runner.RunWith import org.koin.test.AutoCloseKoinTest @@ -22,10 +23,8 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment -import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) -@Config(application = TestApp::class) class UnreadWidgetDataProviderTest : AutoCloseKoinTest() { private val context: Context = RuntimeEnvironment.getApplication() private val account = createAccount() diff --git a/app/common/src/test/java/com/fsck/k9/TestApp.kt b/app/common/src/test/java/com/fsck/k9/TestApp.kt deleted file mode 100644 index c428952d7..000000000 --- a/app/common/src/test/java/com/fsck/k9/TestApp.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.fsck.k9 - -import app.k9mail.core.common.oauth.OAuthConfigurationFactory -import com.fsck.k9.backend.BackendFactory -import org.koin.core.module.Module -import org.koin.core.qualifier.named -import org.koin.dsl.module - -class TestApp : CommonApp() { - override fun provideAppModule(): Module = module { - single(named("ClientIdAppName")) { "ClientIdAppName" } - single(named("ClientIdAppVersion")) { "ClientIdAppVersion" } - single { - AppConfig( - componentsToDisable = emptyList(), - ) - } - single>(named("developmentBackends")) { - emptyMap() - } - single { - OAuthConfigurationFactory { emptyMap() } - } - } -}