issue#103 Close DB to clean up logs
This commit is contained in:
parent
732aa05a87
commit
d057c357a3
1 changed files with 14 additions and 2 deletions
|
|
@ -1,10 +1,12 @@
|
|||
package org.fnives.test.showcase.testutils
|
||||
|
||||
import android.util.Log
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.fnives.test.showcase.BuildConfig
|
||||
import org.fnives.test.showcase.TestShowcaseApplication
|
||||
import org.fnives.test.showcase.di.createAppModules
|
||||
import org.fnives.test.showcase.model.network.BaseUrl
|
||||
import org.fnives.test.showcase.storage.LocalDatabase
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
|
|
@ -14,6 +16,7 @@ import org.koin.core.context.startKoin
|
|||
import org.koin.core.context.stopKoin
|
||||
import org.koin.mp.KoinPlatformTools
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
|
||||
/**
|
||||
* Test rule to help reinitialize the whole Koin setup.
|
||||
|
|
@ -23,16 +26,17 @@ import org.koin.test.KoinTest
|
|||
*
|
||||
* Note: Do not use if you want your test's to share Koin, and in such case do not stop your Koin.
|
||||
*/
|
||||
class ReloadKoinModulesIfNecessaryTestRule : TestRule, KoinTest {
|
||||
class ReloadKoinModulesIfNecessaryTestRule : TestRule {
|
||||
override fun apply(base: Statement, description: Description): Statement =
|
||||
ReinitKoinStatement(base)
|
||||
|
||||
class ReinitKoinStatement(private val base: Statement) : Statement() {
|
||||
class ReinitKoinStatement(private val base: Statement) : Statement(), KoinTest {
|
||||
override fun evaluate() {
|
||||
reinitKoinIfNeeded()
|
||||
try {
|
||||
base.evaluate()
|
||||
} finally {
|
||||
closeDB()
|
||||
stopKoin()
|
||||
}
|
||||
}
|
||||
|
|
@ -48,5 +52,13 @@ class ReloadKoinModulesIfNecessaryTestRule : TestRule, KoinTest {
|
|||
modules(createAppModules(baseUrl))
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeDB() {
|
||||
try {
|
||||
get<LocalDatabase>().close()
|
||||
} catch (ignored: Throwable) {
|
||||
Log.d("ReloadKoinModulesRule", "Could not close db: $ignored, stacktrace: ${ignored.stackTraceToString()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue