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.kt28
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt25
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/utils/UtilsAndroidTest.kt50
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt53
4 files changed, 121 insertions, 35 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 2a9263a..29f5af1 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
@@ -1,9 +1,25 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
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 android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.MediumTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -23,7 +39,7 @@ class KPrefTest {
class TestPref : KPref() {
init {
- initialize(InstrumentationRegistry.getTargetContext(), "kpref_test_${System.currentTimeMillis()}")
+ initialize(ApplicationProvider.getApplicationContext<Context>(), "kpref_test_${System.currentTimeMillis()}")
}
var one by kpref("one", 1)
@@ -83,11 +99,9 @@ class KPrefTest {
assertEquals(-1, pref.one, "Kpref did not refetch from shared prefs upon reset")
}
-
@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 1dac92f..96ebd3a 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt
@@ -1,12 +1,27 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.utils
import android.content.Context
-import android.support.test.InstrumentationRegistry
-import android.support.test.filters.MediumTest
-import android.support.test.runner.AndroidJUnit4
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.MediumTest
+import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -25,7 +40,7 @@ class KotterknifeTest {
@Before
fun init() {
- context = InstrumentationRegistry.getContext()
+ context = InstrumentationRegistry.getInstrumentation().context
}
@Test
@@ -197,4 +212,4 @@ class KotterknifeTest {
view.id = id
return view
}
-} \ No newline at end of file
+}
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/UtilsAndroidTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/UtilsAndroidTest.kt
new file mode 100644
index 0000000..665e0b2
--- /dev/null
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/UtilsAndroidTest.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ca.allanwang.kau.utils
+
+import android.graphics.Color
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+
+/**
+ * Created by Allan Wang on 2018-12-24.
+ *
+ * Misc test code that are dependent on android
+ */
+@RunWith(AndroidJUnit4::class)
+class UtilsAndroidTest {
+
+ @Test
+ fun colorBlend() {
+ assertEquals(0x22446688, 0x11335577.blendWith(0x33557799, 0.5f), "Failed to blend with 50% ratio")
+ assertEquals(0x11335577, 0x11335577.blendWith(0x33557799, 0.0f), "Failed to blend with 0% ratio")
+ assertEquals(0x33557799, 0x22446688.blendWith(0x33557799, 1.0f), "Failed to blend with 100% ratio")
+ }
+
+ @Test
+ fun lighten() {
+ assertEquals(Color.WHITE, Color.WHITE.lighten(0.35f), "Should not be able to further lighten white")
+ assertEquals(0xFFEEAAEA.toInt(), 0xFFDD55D5.toInt().lighten(0.5f), "Failed to lighten color by 50%")
+ }
+
+ @Test
+ fun darken() {
+ assertEquals(Color.BLACK, Color.BLACK.darken(0.35f), "Should not be able to further darken black")
+ assertEquals(0xFF224424.toInt(), 0xFF448848.toInt().darken(0.5f), "Failed to darken color by 50%")
+ }
+}
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt
index f9ce24b..7ec2a41 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt
@@ -1,8 +1,25 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.xml
-import android.support.test.InstrumentationRegistry
-import android.support.test.filters.MediumTest
-import android.support.test.runner.AndroidJUnit4
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.MediumTest
+import ca.allanwang.kau.test.R
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals
@@ -14,26 +31,16 @@ import kotlin.test.assertEquals
@MediumTest
class FaqTest {
- @Test
- fun simpleTest() {
- InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq) { data ->
- assertEquals(2, data.size, "FAQ size is incorrect")
- assertEquals("1. This is a question", data.first().question.toString(), "First question does not match")
- assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match")
- assertEquals("2. This is another question", data.last().question.toString(), "Second question does not match")
- assertEquals("This is another answer", data.last().answer.toString(), "Second answer does not match")
- }
- }
+ val context: Context
+ get() = ApplicationProvider.getApplicationContext<Context>()
@Test
- fun withoutNumbering() {
- InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq, false) { data ->
- assertEquals(2, data.size, "FAQ size is incorrect")
- assertEquals("This is a question", data.first().question.toString(), "First question does not match")
- assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match")
- assertEquals("This is another question", data.last().question.toString(), "Second question does not match")
- assertEquals("This is another answer", data.last().answer.toString(), "Second answer does not match")
- }
+ fun simpleTest() {
+ val data = context.kauParseFaq(R.xml.test_faq, false)
+ assertEquals(2, data.size, "FAQ size is incorrect")
+ assertEquals("This is a question", data.first().question.toString(), "First question does not match")
+ assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match")
+ assertEquals("This is another question", data.last().question.toString(), "Second question does not match")
+ assertEquals("This is another answer", data.last().answer.toString(), "Second answer does not match")
}
-
-} \ No newline at end of file
+}