aboutsummaryrefslogtreecommitdiff
path: root/app/src
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
parentb5d442ba3c86500b23d5bff8f1eb80ab51d1ccfa (diff)
downloadfrost-cd0e7549d4a9876923649b83bbc82dab9caa0232.tar.gz
frost-cd0e7549d4a9876923649b83bbc82dab9caa0232.tar.bz2
frost-cd0e7549d4a9876923649b83bbc82dab9caa0232.zip
Split db tests per dao
Diffstat (limited to 'app/src')
-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