diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-02 16:21:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 16:21:49 -0700 |
commit | 53382b44bb7ab7ccb559e96fd1f93c47020878ee (patch) | |
tree | 79c1862992f458ac52c1910b3a2e0c01cb7d5a5a /core/src/androidTest/kotlin/ca/allanwang/kau/kpref | |
parent | 7d894be6de118357ec908d2d171b6152ce67307d (diff) | |
download | kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.tar.gz kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.tar.bz2 kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.zip |
Improve video prefetching (#17)
* Create base activity and add thumbnails to media picker
* Add checker to see if requested permission is inside the manifest
* Add faq parser with tests
* Add kpref testers and expose sp
* Test jitpack sample exclusion
* Test caching
* Improve glide caching
Diffstat (limited to 'core/src/androidTest/kotlin/ca/allanwang/kau/kpref')
-rw-r--r-- | core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 85 |
1 files changed, 85 insertions, 0 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 new file mode 100644 index 0000000..e806a3f --- /dev/null +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -0,0 +1,85 @@ +package ca.allanwang.kau.kpref + +import android.annotation.SuppressLint +import android.support.test.InstrumentationRegistry +import android.support.test.filters.MediumTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +/** + * Created by Allan Wang on 2017-08-01. + */ +@RunWith(AndroidJUnit4::class) +@MediumTest +class ChangelogTest { + + lateinit var pref: TestPref + + class TestPref : KPref() { + init { + initialize(InstrumentationRegistry.getTargetContext(), "kpref_test_${System.currentTimeMillis()}") + } + + var one: Int by kpref("one", 1) + + var `true`: Boolean by kpref("true", true) + + var hello: String by kpref("hello", "hello") + + var set: StringSet by kpref("set", setOf("po", "ta", "to")) + + val oneShot: Boolean by kprefSingle("asdf") + } + + @Before + fun init() { + pref = TestPref() + } + + @Test + fun getDefaults() { + assertEquals(1, pref.one) + 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")) + } + + @Test + fun setter() { + assertEquals(1, pref.one) + pref.one = 2 + assertEquals(2, pref.one) + pref.hello = "goodbye" + assertEquals("goodbye", pref.hello) + assertEquals(pref.hello, pref.sp.getString("hello", "hello")) + } + + @SuppressLint("CommitPrefEdits") + @Test + fun reset() { + pref.one = 2 + assertEquals(2, pref.one) + pref.reset() //only invalidates our lazy delegate; doesn't change the actual pref + assertEquals(2, pref.one) + pref.sp.edit().putInt("one", -1).commit() + assertEquals(2, pref.one) //our lazy delegate still retains the old value + pref.reset() + assertEquals(-1, pref.one) //back in sync with sp + } + + + @Test + fun single() { + assertTrue(pref.oneShot) + assertFalse(pref.oneShot) + } + +}
\ No newline at end of file |