This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from corona-warn-app/dev
0.8.2
- Loading branch information
Showing
138 changed files
with
5,036 additions
and
3,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/storage/ExposureSummaryDaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package de.rki.coronawarnapp.storage | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* ExposureSummaryDao test. | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExposureSummaryDaoTest { | ||
private lateinit var dao: ExposureSummaryDao | ||
private lateinit var db: AppDatabase | ||
|
||
@Before | ||
fun setUp() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
db = Room.inMemoryDatabaseBuilder( | ||
context, AppDatabase::class.java).build() | ||
dao = db.exposureSummaryDao() | ||
} | ||
|
||
/** | ||
* Test Create / Read DB operations. | ||
*/ | ||
@Test | ||
fun testCROperations() { | ||
runBlocking { | ||
val testEntity1 = ExposureSummaryEntity().apply { | ||
this.daysSinceLastExposure = 1 | ||
this.matchedKeyCount = 1 | ||
this.maximumRiskScore = 1 | ||
this.summationRiskScore = 1 | ||
} | ||
|
||
val testEntity2 = ExposureSummaryEntity().apply { | ||
this.daysSinceLastExposure = 2 | ||
this.matchedKeyCount = 2 | ||
this.maximumRiskScore = 2 | ||
this.summationRiskScore = 2 | ||
} | ||
|
||
assertThat(dao.getExposureSummaryEntities().isEmpty()).isTrue() | ||
|
||
val id1 = dao.insertExposureSummaryEntity(testEntity1) | ||
var selectAll = dao.getExposureSummaryEntities() | ||
var selectLast = dao.getLatestExposureSummary() | ||
assertThat(dao.getExposureSummaryEntities().isEmpty()).isFalse() | ||
assertThat(selectAll.size).isEqualTo(1) | ||
assertThat(selectAll[0].id).isEqualTo(id1) | ||
assertThat(selectLast).isNotNull() | ||
assertThat(selectLast?.id).isEqualTo(id1) | ||
|
||
val id2 = dao.insertExposureSummaryEntity(testEntity2) | ||
selectAll = dao.getExposureSummaryEntities() | ||
selectLast = dao.getLatestExposureSummary() | ||
assertThat(selectAll.isEmpty()).isFalse() | ||
assertThat(selectAll.size).isEqualTo(2) | ||
assertThat(selectLast).isNotNull() | ||
assertThat(selectLast?.id).isEqualTo(id2) | ||
} | ||
} | ||
|
||
@After | ||
fun closeDb() { | ||
db.close() | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...na-Warn-App/src/androidTest/java/de/rki/coronawarnapp/storage/keycache/KeyCacheDaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package de.rki.coronawarnapp.storage.keycache | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth.assertThat | ||
import de.rki.coronawarnapp.storage.AppDatabase | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* KeyCacheDao test. | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class KeyCacheDaoTest { | ||
private lateinit var keyCacheDao: KeyCacheDao | ||
private lateinit var db: AppDatabase | ||
|
||
@Before | ||
fun setUp() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
db = Room.inMemoryDatabaseBuilder( | ||
context, AppDatabase::class.java).build() | ||
keyCacheDao = db.dateDao() | ||
} | ||
|
||
/** | ||
* Test Create / Read / Delete DB operations. | ||
*/ | ||
@Test | ||
fun testCRDOperations() { | ||
runBlocking { | ||
val dates = KeyCacheEntity().apply { | ||
this.id = "0" | ||
this.path = "0" | ||
this.type = 0 | ||
} | ||
val hours = KeyCacheEntity().apply { | ||
this.id = "1" | ||
this.path = "1" | ||
this.type = 1 | ||
} | ||
|
||
assertThat(keyCacheDao.getAllEntries().isEmpty()).isTrue() | ||
|
||
keyCacheDao.insertEntry(dates) | ||
keyCacheDao.insertEntry(hours) | ||
|
||
var all = keyCacheDao.getAllEntries() | ||
|
||
assertThat(all.size).isEqualTo(2) | ||
|
||
val selectedDates = keyCacheDao.getDates() | ||
assertThat(selectedDates.size).isEqualTo(1) | ||
assertThat(selectedDates[0].type).isEqualTo(0) | ||
assertThat(selectedDates[0].id).isEqualTo(dates.id) | ||
|
||
val selectedHours = keyCacheDao.getHours() | ||
assertThat(selectedHours.size).isEqualTo(1) | ||
assertThat(selectedHours[0].type).isEqualTo(1) | ||
assertThat(selectedHours[0].id).isEqualTo(hours.id) | ||
|
||
keyCacheDao.clearHours() | ||
|
||
all = keyCacheDao.getAllEntries() | ||
assertThat(all.size).isEqualTo(1) | ||
assertThat(all[0].type).isEqualTo(0) | ||
|
||
keyCacheDao.insertEntry(hours) | ||
|
||
assertThat(keyCacheDao.getAllEntries().size).isEqualTo(2) | ||
|
||
keyCacheDao.clear() | ||
|
||
assertThat(keyCacheDao.getAllEntries().isEmpty()).isTrue() | ||
} | ||
} | ||
|
||
@After | ||
fun closeDb() { | ||
db.close() | ||
} | ||
} |
Oops, something went wrong.