diff options
author | Allan Wang <me@allanwang.ca> | 2018-10-08 01:46:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-08 01:46:36 -0400 |
commit | 19020070cc073c81bfe397454f2314d37a78ed31 (patch) | |
tree | 7cebfa93ec8f8b465608579744b34be0aed0b1cc /core/src/androidTest | |
parent | 81518f74fa76b6c2274a0e02ad4169f5d7f61e59 (diff) | |
download | kau-19020070cc073c81bfe397454f2314d37a78ed31.tar.gz kau-19020070cc073c81bfe397454f2314d37a78ed31.tar.bz2 kau-19020070cc073c81bfe397454f2314d37a78ed31.zip |
Enhancement/kpref (#170)
* Deprecate kpref double
* Update kpref tests and migration
* Fix kpref file
* Update changelog
* Replace changelog angle brackets
Diffstat (limited to 'core/src/androidTest')
-rw-r--r-- | core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt index e806a3f..2a9263a 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -16,40 +16,46 @@ import kotlin.test.assertTrue */ @RunWith(AndroidJUnit4::class) @MediumTest -class ChangelogTest { +class KPrefTest { lateinit var pref: TestPref class TestPref : KPref() { + init { initialize(InstrumentationRegistry.getTargetContext(), "kpref_test_${System.currentTimeMillis()}") } - var one: Int by kpref("one", 1) + var one by kpref("one", 1) + + var two by kpref("two", 2f) - var `true`: Boolean by kpref("true", true) + var `true` by kpref("true", true) - var hello: String by kpref("hello", "hello") + var hello by kpref("hello", "hello") - var set: StringSet by kpref("set", setOf("po", "ta", "to")) + var set by kpref("set", setOf("po", "ta", "to")) - val oneShot: Boolean by kprefSingle("asdf") + val oneShot by kprefSingle("asdf") } @Before fun init() { pref = TestPref() + pref.sp.edit().clear().commit() } @Test fun getDefaults() { assertEquals(1, pref.one) + assertEquals(2f, pref.two) assertEquals(true, pref.`true`) assertEquals("hello", pref.hello) assertEquals(3, pref.set.size) assertTrue(pref.set.contains("po")) assertTrue(pref.set.contains("ta")) assertTrue(pref.set.contains("to")) + assertEquals(0, pref.sp.all.size, "Defaults should not be set automatically") } @Test @@ -60,6 +66,7 @@ class ChangelogTest { pref.hello = "goodbye" assertEquals("goodbye", pref.hello) assertEquals(pref.hello, pref.sp.getString("hello", "hello")) + assertEquals(2, pref.sp.all.size) } @SuppressLint("CommitPrefEdits") @@ -67,12 +74,13 @@ class ChangelogTest { fun reset() { pref.one = 2 assertEquals(2, pref.one) + assertEquals(6, pref.prefMap.size, "Prefmap does not have all elements") pref.reset() //only invalidates our lazy delegate; doesn't change the actual pref - assertEquals(2, pref.one) + assertEquals(2, pref.one, "Kpref did not properly fetch from shared prefs") pref.sp.edit().putInt("one", -1).commit() - assertEquals(2, pref.one) //our lazy delegate still retains the old value + assertEquals(2, pref.one, "Lazy kpref should still retain old value") pref.reset() - assertEquals(-1, pref.one) //back in sync with sp + assertEquals(-1, pref.one, "Kpref did not refetch from shared prefs upon reset") } |