diff --git a/app/src/main/java/com/stevesoltys/seedvault/App.kt b/app/src/main/java/com/stevesoltys/seedvault/App.kt index 295f906a..a99e08a6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/App.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/App.kt @@ -34,7 +34,7 @@ import org.koin.dsl.module * @author Steve Soltys * @author Torsten Grote */ -class App : Application() { +open class App : Application() { private val appModule = module { single { SettingsManager(this@App) } @@ -52,22 +52,7 @@ class App : Application() { override fun onCreate() { super.onCreate() - startKoin { - androidLogger() - androidContext(this@App) - modules( - listOf( - cryptoModule, - headerModule, - metadataModule, - documentsProviderModule, // storage plugin - backupModule, - restoreModule, - installModule, - appModule - ) - ) - } + startKoin() if (isDebugBuild()) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() @@ -88,6 +73,23 @@ class App : Application() { } } + protected open fun startKoin() = startKoin { + androidLogger() + androidContext(this@App) + modules( + listOf( + cryptoModule, + headerModule, + metadataModule, + documentsProviderModule, // storage plugin + backupModule, + restoreModule, + installModule, + appModule + ) + ) + } + private val settingsManager: SettingsManager by inject() private val metadataManager: MetadataManager by inject() diff --git a/app/src/test/java/com/stevesoltys/seedvault/TestApp.kt b/app/src/test/java/com/stevesoltys/seedvault/TestApp.kt new file mode 100644 index 00000000..b1ad45a5 --- /dev/null +++ b/app/src/test/java/com/stevesoltys/seedvault/TestApp.kt @@ -0,0 +1,45 @@ +package com.stevesoltys.seedvault + +import com.stevesoltys.seedvault.crypto.CipherFactory +import com.stevesoltys.seedvault.crypto.CipherFactoryImpl +import com.stevesoltys.seedvault.crypto.Crypto +import com.stevesoltys.seedvault.crypto.CryptoImpl +import com.stevesoltys.seedvault.crypto.KeyManager +import com.stevesoltys.seedvault.crypto.KeyManagerTestImpl +import com.stevesoltys.seedvault.header.headerModule +import com.stevesoltys.seedvault.metadata.metadataModule +import com.stevesoltys.seedvault.plugins.saf.documentsProviderModule +import com.stevesoltys.seedvault.restore.install.installModule +import com.stevesoltys.seedvault.transport.backup.backupModule +import com.stevesoltys.seedvault.transport.restore.restoreModule +import org.koin.android.ext.koin.androidContext +import org.koin.core.context.startKoin +import org.koin.dsl.module + +class TestApp : App() { + + private val testCryptoModule = module { + factory { CipherFactoryImpl(get()) } + single { KeyManagerTestImpl() } + single { CryptoImpl(get(), get(), get()) } + } + private val appModule = module { + single { Clock() } + } + + override fun startKoin() = startKoin { + androidContext(this@TestApp) + modules( + listOf( + testCryptoModule, + headerModule, + metadataModule, + documentsProviderModule, // storage plugin + backupModule, + restoreModule, + installModule, + appModule + ) + ) + } +} diff --git a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt index 6b356016..0aae4113 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt @@ -8,6 +8,7 @@ import android.content.pm.ApplicationInfo.FLAG_SYSTEM import android.content.pm.PackageInfo import androidx.test.ext.junit.runners.AndroidJUnit4 import com.stevesoltys.seedvault.Clock +import com.stevesoltys.seedvault.TestApp import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.getRandomString import com.stevesoltys.seedvault.metadata.PackageState.APK_AND_DATA @@ -37,7 +38,10 @@ import kotlin.random.Random @Suppress("DEPRECATION") @RunWith(AndroidJUnit4::class) -@Config(sdk = [29]) // robolectric does not support 30, yet +@Config( + sdk = [29], // robolectric does not support 30, yet + application = TestApp::class +) class MetadataManagerTest { private val context: Context = mockk() diff --git a/app/src/test/java/com/stevesoltys/seedvault/plugins/saf/DocumentFileTest.kt b/app/src/test/java/com/stevesoltys/seedvault/plugins/saf/DocumentFileTest.kt index 83ed6e29..49a182e4 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/plugins/saf/DocumentFileTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/plugins/saf/DocumentFileTest.kt @@ -5,6 +5,7 @@ import android.net.Uri import android.provider.DocumentsContract import androidx.documentfile.provider.DocumentFile import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.stevesoltys.seedvault.TestApp import io.mockk.mockk import org.junit.After import org.junit.Assert.assertEquals @@ -15,7 +16,10 @@ import org.koin.core.context.stopKoin import org.robolectric.annotation.Config @RunWith(AndroidJUnit4::class) -@Config(sdk = [29]) // robolectric does not support 30, yet +@Config( + sdk = [29], // robolectric does not support 30, yet + application = TestApp::class +) internal class DocumentFileTest { private val context: Context = mockk() diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/DeviceInfoTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/DeviceInfoTest.kt index 4afe4ec7..414f5c1d 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/DeviceInfoTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/DeviceInfoTest.kt @@ -6,6 +6,7 @@ import android.util.DisplayMetrics import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.stevesoltys.seedvault.R +import com.stevesoltys.seedvault.TestApp import com.stevesoltys.seedvault.getRandomString import io.mockk.every import io.mockk.mockk @@ -20,7 +21,10 @@ import org.robolectric.annotation.Config import kotlin.random.Random @RunWith(AndroidJUnit4::class) -@Config(sdk = [29]) // robolectric does not support 30, yet +@Config( + sdk = [29], // robolectric does not support 30, yet + application = TestApp::class +) internal class DeviceInfoTest { @After