aboutsummaryrefslogtreecommitdiff
path: root/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt48
1 files changed, 48 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..417c6678
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2019 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+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.save(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})"
+ )
+ }
+ }
+}