aboutsummaryrefslogtreecommitdiff
path: root/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-05 19:21:17 -0500
committerAllan Wang <me@allanwang.ca>2019-03-05 19:21:17 -0500
commitcd0e7549d4a9876923649b83bbc82dab9caa0232 (patch)
tree411ed35923bf44350c400071b0f6ddfa02bebd15 /app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
parentb5d442ba3c86500b23d5bff8f1eb80ab51d1ccfa (diff)
downloadfrost-cd0e7549d4a9876923649b83bbc82dab9caa0232.tar.gz
frost-cd0e7549d4a9876923649b83bbc82dab9caa0232.tar.bz2
frost-cd0e7549d4a9876923649b83bbc82dab9caa0232.zip
Split db tests per dao
Diffstat (limited to 'app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
new file mode 100644
index 00000000..351490e2
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
@@ -0,0 +1,67 @@
+package com.pitchedapps.frost.db
+
+import kotlinx.coroutines.runBlocking
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNull
+
+class CookieDbTest : BaseDbTest() {
+
+ @Test
+ fun basicCookie() {
+ val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
+ runBlocking {
+ db.cookieDao().insertCookie(cookie)
+ val cookies = db.cookieDao().selectAll()
+ assertEquals(listOf(cookie), cookies, "Cookie mismatch")
+ }
+ }
+
+ @Test
+ fun deleteCookie() {
+ val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
+
+ runBlocking {
+ db.cookieDao().insertCookie(cookie)
+ db.cookieDao().deleteById(cookie.id + 1)
+ assertEquals(
+ listOf(cookie),
+ db.cookieDao().selectAll(),
+ "Cookie list should be the same after inexistent deletion"
+ )
+ db.cookieDao().deleteById(cookie.id)
+ assertEquals(emptyList(), db.cookieDao().selectAll(), "Cookie list should be empty after deletion")
+ }
+ }
+
+ @Test
+ fun insertReplaceCookie() {
+ val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
+ runBlocking {
+ db.cookieDao().insertCookie(cookie)
+ assertEquals(listOf(cookie), db.cookieDao().selectAll(), "Cookie insertion failed")
+ db.cookieDao().insertCookie(cookie.copy(name = "testName2"))
+ assertEquals(
+ listOf(cookie.copy(name = "testName2")),
+ db.cookieDao().selectAll(),
+ "Cookie replacement failed"
+ )
+ db.cookieDao().insertCookie(cookie.copy(id = 123L))
+ assertEquals(
+ setOf(cookie.copy(id = 123L), cookie.copy(name = "testName2")),
+ db.cookieDao().selectAll().toSet(),
+ "New cookie insertion failed"
+ )
+ }
+ }
+
+ @Test
+ fun selectCookie() {
+ val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
+ runBlocking {
+ db.cookieDao().insertCookie(cookie)
+ assertEquals(cookie, db.cookieDao().selectById(cookie.id), "Cookie selection failed")
+ assertNull(db.cookieDao().selectById(cookie.id + 1), "Inexistent cookie selection failed")
+ }
+ }
+} \ No newline at end of file