aboutsummaryrefslogtreecommitdiff
path: root/core/src/androidTest
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/androidTest')
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt85
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt4
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/xml/ChangelogTest.kt4
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt38
-rw-r--r--core/src/androidTest/res/xml/test_changelog.xml12
-rw-r--r--core/src/androidTest/res/xml/test_faq.xml9
-rw-r--r--core/src/androidTest/res/xml/text_changelog.xml11
7 files changed, 149 insertions, 14 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
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt
index 3282911..1dac92f 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt
@@ -7,10 +7,12 @@ import android.support.test.runner.AndroidJUnit4
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
-import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
/**
* Created by Allan Wang on 2017-07-30.
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/ChangelogTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/ChangelogTest.kt
index dcff70e..a3c9ff1 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/ChangelogTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/ChangelogTest.kt
@@ -14,9 +14,9 @@ import org.junit.runner.RunWith
@MediumTest
class ChangelogTest {
- @Test
+// @Test //todo internal function sharing is only available on gradle 3.0.0+
fun simpleTest() {
- val data = parse(InstrumentationRegistry.getTargetContext(), R.xml.text_changelog)
+// val data = parse(InstrumentationRegistry.getTargetContext(), R.xml.test_changelog)
}
} \ No newline at end of file
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt
new file mode 100644
index 0000000..94d1330
--- /dev/null
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt
@@ -0,0 +1,38 @@
+package ca.allanwang.kau.xml
+
+import android.support.test.InstrumentationRegistry
+import android.support.test.filters.MediumTest
+import android.support.test.runner.AndroidJUnit4
+import ca.allanwang.kau.test.R
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+
+/**
+ * Created by Allan Wang on 2017-08-01.
+ */
+@RunWith(AndroidJUnit4::class)
+@MediumTest
+class FaqTest {
+
+ @Test
+ fun simpleTest() {
+ val data = InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq)
+ assertEquals(2, data.size, "FAQ size is incorrect")
+ assertEquals("1. This is a question", data.first().first.toString(), "First question does not match")
+ assertEquals("This is an answer", data.first().second.toString(), "First answer does not match")
+ assertEquals("2. This is another question", data.last().first.toString(), "Second question does not match")
+ assertEquals("This is another answer", data.last().second.toString(), "Second answer does not match")
+ }
+
+ @Test
+ fun withoutNumbering() {
+ val data = InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq, false)
+ assertEquals(2, data.size, "FAQ size is incorrect")
+ assertEquals("This is a question", data.first().first.toString(), "First question does not match")
+ assertEquals("This is an answer", data.first().second.toString(), "First answer does not match")
+ assertEquals("This is another question", data.last().first.toString(), "Second question does not match")
+ assertEquals("This is another answer", data.last().second.toString(), "Second answer does not match")
+ }
+
+} \ No newline at end of file
diff --git a/core/src/androidTest/res/xml/test_changelog.xml b/core/src/androidTest/res/xml/test_changelog.xml
new file mode 100644
index 0000000..2e90561
--- /dev/null
+++ b/core/src/androidTest/res/xml/test_changelog.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <version title="v1.1"/>
+ <item text="This is version 1.1" />
+ <item text="This is the last line to be displayed" />
+ <item text="" />
+
+ <version title="v1.0"/>
+ <item text="potato 1.0" />
+
+</resources> \ No newline at end of file
diff --git a/core/src/androidTest/res/xml/test_faq.xml b/core/src/androidTest/res/xml/test_faq.xml
new file mode 100644
index 0000000..4905df3
--- /dev/null
+++ b/core/src/androidTest/res/xml/test_faq.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <question>This is a question</question>
+ <answer>This is an answer</answer>
+ <question>This is another question</question>
+ <answer>This is another answer</answer>
+
+</resources> \ No newline at end of file
diff --git a/core/src/androidTest/res/xml/text_changelog.xml b/core/src/androidTest/res/xml/text_changelog.xml
deleted file mode 100644
index 6294144..0000000
--- a/core/src/androidTest/res/xml/text_changelog.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
-
- <version title="title1"/>
- <item text="test case" />
- <item text="" />
-
- <version title="title2"/>
- <item text="potato" />
-
-</resources> \ No newline at end of file