aboutsummaryrefslogtreecommitdiff
path: root/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-02-23 13:02:25 -0800
committerAllan Wang <me@allanwang.ca>2020-02-23 13:02:25 -0800
commitd67d4a1204796377040a1769175d5798ce09408b (patch)
tree253eda7836828255e65bf1b22436346338c73ac0 /sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
parentce0ae639188dad9ca212667c59131c04de1ed575 (diff)
downloadkau-d67d4a1204796377040a1769175d5798ce09408b.tar.gz
kau-d67d4a1204796377040a1769175d5798ce09408b.tar.bz2
kau-d67d4a1204796377040a1769175d5798ce09408b.zip
Fix kpref tests
Diffstat (limited to 'sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt')
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt41
1 files changed, 18 insertions, 23 deletions
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
index 5847a94..156b66f 100644
--- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
@@ -26,7 +26,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
-import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
@@ -35,13 +34,11 @@ import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.instanceOf
import org.junit.Rule
import org.junit.Test
+import org.junit.rules.RuleChain
+import org.junit.rules.TestRule
import org.junit.runner.RunWith
-import org.koin.android.ext.koin.androidContext
-import org.koin.core.context.startKoin
-import org.koin.core.context.stopKoin
import org.koin.test.KoinTest
import org.koin.test.inject
-import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@@ -55,24 +52,18 @@ import kotlin.test.assertTrue
@MediumTest
class KPrefViewTest : KoinTest {
- @get:Rule
val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
+ @get:Rule
+ val rule: TestRule = RuleChain.outerRule(SampleTestRule()).around(activity)
+
+ private val pref: KPrefSample by inject()
+
@BeforeTest
fun before() {
- startKoin {
- androidContext(InstrumentationRegistry.getInstrumentation().context)
- modules(listOf(SampleApp.prefModule(), SampleTestApp.prefFactoryModule()))
- }
- }
-
- @AfterTest
- fun after() {
- stopKoin()
+ pref.reset()
}
- private val pref: KPrefSample by inject()
-
fun verifyCheck(checked: Boolean): Matcher<View> {
return object : BoundedMatcher<View, View>(View::class.java) {
@@ -132,20 +123,24 @@ class KPrefViewTest : KoinTest {
fun dependentCheckboxToggle() {
val checkbox2 = onCheckboxView(withChild(withText(R.string.checkbox_2)))
val checkbox3 =
- onCheckboxView(withChild(withText(R.string.checkbox_3)), withChild(withText(R.string.desc_dependent)))
+ onCheckboxView(
+ withChild(withText(R.string.checkbox_3)),
+ withChild(withText(R.string.desc_dependent))
+ )
assertFalse(pref.check2, "check2 not normalized")
assertFalse(pref.check3, "check3 not normalized")
- checkbox3.verifyCheck("checkbox3 init", true, true)
+ checkbox2.verifyCheck("checkbox2 init", checked = false, enabled = true)
+ checkbox3.verifyCheck("checkbox3 init", checked = false, enabled = false)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after click", false, true)
+ checkbox3.verifyCheck("checkbox3 after disabled click", checked = false, enabled = false)
checkbox2.perform(click())
- checkbox2.verifyCheck("checkbox2 after click", false, true)
- checkbox3.verifyCheck("checkbox3 after checkbox2 click", false, false)
+ checkbox2.verifyCheck("checkbox2 after click", checked = true, enabled = true)
+ checkbox3.verifyCheck("checkbox3 after checkbox2 click", checked = false, enabled = true)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after disabled click", false, false)
+ checkbox3.verifyCheck("checkbox3 after enabled click", checked = true, enabled = true)
}
}