Add getOfflineRegion Kotlin API (#2516)

This commit is contained in:
JRW
2024-08-08 15:49:49 +01:00
committed by GitHub
parent f4fc63bdc0
commit 9432d805cd
9 changed files with 274 additions and 4 deletions

View File

@@ -100,7 +100,7 @@ class OfflineManagerTest : AppCenter() {
// List regions (ensure merge yielded one region only)
val latch3 = CountDownLatch(1)
val latch3 = CountDownLatch(2)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>?) {
@@ -114,6 +114,29 @@ class OfflineManagerTest : AppCenter() {
}
})
}
val regionID = 1L
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).getOfflineRegion(
regionID,
object: OfflineManager.GetOfflineRegionCallback {
override fun onRegion(offlineRegion: OfflineRegion) {
Assert.assertNotNull(offlineRegion)
Assert.assertEquals(regionID, offlineRegion!!.id)
Assert.assertNotNull(offlineRegion.definition)
latch3.countDown()
}
override fun onRegionNotFound() {
throw RuntimeException("Region should be in database")
}
override fun onError(error: String) {
throw RuntimeException("Unable to get region in offline database. $error")
}
}
)
}
latch3.await()
// Invalidate region
@@ -150,7 +173,7 @@ class OfflineManagerTest : AppCenter() {
// List regions (ensure deletion was successful)
val latch6 = CountDownLatch(1)
val latch6 = CountDownLatch(2)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>?) {
@@ -163,6 +186,25 @@ class OfflineManagerTest : AppCenter() {
}
})
}
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).getOfflineRegion(
regionID,
object: OfflineManager.GetOfflineRegionCallback {
override fun onRegion(offlineRegion: OfflineRegion) {
throw RuntimeException("Region should not be in database")
}
override fun onRegionNotFound() {
latch6.countDown()
}
override fun onError(error: String) {
throw RuntimeException("Unable to get offline region from db. $error")
}
}
)
}
latch6.await()
}
}