aboutsummaryrefslogtreecommitdiff
path: root/app/src/androidTest/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-07 14:59:40 -0500
committerAllan Wang <me@allanwang.ca>2019-03-07 14:59:40 -0500
commit12f491737ec2e2d774a816e84170ff352d1b6cd6 (patch)
treef61b20f5ba7630fecef50976733e26fbc4ef5a52 /app/src/androidTest/kotlin
parentf1878133d8af686ce8c27acffe28f26e9dda5165 (diff)
downloadfrost-12f491737ec2e2d774a816e84170ff352d1b6cd6.tar.gz
frost-12f491737ec2e2d774a816e84170ff352d1b6cd6.tar.bz2
frost-12f491737ec2e2d774a816e84170ff352d1b6cd6.zip
Add cache test
Diffstat (limited to 'app/src/androidTest/kotlin')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
new file mode 100644
index 00000000..780bbd3e
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
@@ -0,0 +1,32 @@
+package com.pitchedapps.frost.db
+
+import kotlinx.coroutines.runBlocking
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+import kotlin.test.fail
+
+class CacheDbTest : BaseDbTest() {
+
+ private val dao get() = db.cacheDao()
+ private val cookieDao get() = db.cookieDao()
+
+ private fun cookie(id: Long) = CookieEntity(id, "name$id", "cookie$id")
+
+ @Test
+ fun save() {
+ val cookie = cookie(1L)
+ val type = "test"
+ val content = "long test".repeat(10000)
+ runBlocking {
+ cookieDao.insertCookie(cookie)
+ dao.save(cookie.id, type, content)
+ val cache = dao.select(cookie.id, type) ?: fail("Cache not found")
+ assertEquals(content, cache.contents, "Content mismatch")
+ assertTrue(
+ System.currentTimeMillis() - cache.lastUpdated < 500,
+ "Cache retrieval took over 500ms (${System.currentTimeMillis() - cache.lastUpdated})"
+ )
+ }
+ }
+} \ No newline at end of file