aboutsummaryrefslogtreecommitdiff
path: root/app/src/androidTest/kotlin/com
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/kotlin/com')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/BaseDbTest.kt32
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt (renamed from app/src/androidTest/kotlin/com/pitchedapps/frost/db/FrostDatabaseTest.kt)42
2 files changed, 45 insertions, 29 deletions
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/BaseDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/BaseDbTest.kt
new file mode 100644
index 00000000..6621ea95
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/BaseDbTest.kt
@@ -0,0 +1,32 @@
+package com.pitchedapps.frost.db
+
+import android.content.Context
+import androidx.room.Room
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.runner.RunWith
+import kotlin.test.AfterTest
+import kotlin.test.BeforeTest
+
+@RunWith(AndroidJUnit4::class)
+abstract class BaseDbTest {
+
+ protected lateinit var db: FrostDatabase
+
+ @BeforeTest
+ fun before() {
+ val context = ApplicationProvider.getApplicationContext<Context>()
+ val privateDb = Room.inMemoryDatabaseBuilder(
+ context, FrostPrivateDatabase::class.java
+ ).build()
+ val publicDb = Room.inMemoryDatabaseBuilder(
+ context, FrostPublicDatabase::class.java
+ ).build()
+ db = FrostDatabase(privateDb, publicDb)
+ }
+
+ @AfterTest
+ fun after() {
+ db.close()
+ }
+} \ No newline at end of file
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/FrostDatabaseTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
index dcc96c2d..351490e2 100644
--- a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/FrostDatabaseTest.kt
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
@@ -1,37 +1,11 @@
package com.pitchedapps.frost.db
-import android.content.Context
-import androidx.room.Room
-import androidx.test.core.app.ApplicationProvider
-import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.runBlocking
-import org.junit.runner.RunWith
-import kotlin.test.AfterTest
-import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertNull
-@RunWith(AndroidJUnit4::class)
-class FrostDatabaseTest {
-
- private lateinit var db: FrostDatabase
-
- @BeforeTest
- fun before() {
- val context = ApplicationProvider.getApplicationContext<Context>()
- val privateDb = Room.inMemoryDatabaseBuilder(
- context, FrostPrivateDatabase::class.java
- ).build()
- val publicDb = Room.inMemoryDatabaseBuilder(
- context, FrostPublicDatabase::class.java
- ).build()
- db = FrostDatabase(privateDb, publicDb)
- }
-
- @AfterTest
- fun after() {
- db.close()
- }
+class CookieDbTest : BaseDbTest() {
@Test
fun basicCookie() {
@@ -61,7 +35,7 @@ class FrostDatabaseTest {
}
@Test
- fun insertCookie() {
+ fun insertReplaceCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
db.cookieDao().insertCookie(cookie)
@@ -80,4 +54,14 @@ class FrostDatabaseTest {
)
}
}
+
+ @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