diff options
author | Allan Wang <me@allanwang.ca> | 2017-05-30 17:26:14 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-05-30 17:26:14 -0700 |
commit | 20ef6500dc0b6d84905d92d8469feb6ff0ac502d (patch) | |
tree | 89a8d9a5132fee000aa2fa6ef641905239c38106 /app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt | |
parent | 4c44dbc9933bd726c1da0bf326102835c4974d6b (diff) | |
download | frost-20ef6500dc0b6d84905d92d8469feb6ff0ac502d.tar.gz frost-20ef6500dc0b6d84905d92d8469feb6ff0ac502d.tar.bz2 frost-20ef6500dc0b6d84905d92d8469feb6ff0ac502d.zip |
migrate to dbflow
Diffstat (limited to 'app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt')
-rw-r--r-- | app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt b/app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt new file mode 100644 index 00000000..aaf38a0f --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/DbFlowTestRule.kt @@ -0,0 +1,38 @@ +package com.pitchedapps.frost + +import com.raizlabs.android.dbflow.config.DatabaseConfig +import com.raizlabs.android.dbflow.config.FlowConfig +import com.raizlabs.android.dbflow.config.FlowManager +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement +import org.robolectric.RuntimeEnvironment + +/** + * Created by Allan Wang on 2017-05-30. + */ + +class DBFlowTestRule : TestRule { + + override fun apply(base: Statement, description: Description): Statement { + return object : Statement() { + + @Throws(Throwable::class) + override fun evaluate() { + FlowManager.init(FlowConfig.Builder(RuntimeEnvironment.application) + .addDatabaseConfig(DatabaseConfig.Builder(TestDatabase::class.java) + .transactionManagerCreator(::ImmediateTransactionManager) + .build()).build()) + try { + base.evaluate() + } finally { + FlowManager.destroy() + } + } + } + } + + companion object { + fun create() = DBFlowTestRule() + } +}
\ No newline at end of file |