File tree Expand file tree Collapse file tree 2 files changed +10
-20
lines changed
main/java/org/smartregister/fhircore/engine/sync
test/java/org/smartregister/fhircore/engine/sync Expand file tree Collapse file tree 2 files changed +10
-20
lines changed Original file line number Diff line number Diff line change 1616
1717package org.smartregister.fhircore.engine.sync
1818
19+ import android.content.Context
1920import com.google.android.fhir.FhirEngine
2021import com.google.android.fhir.sync.AcceptLocalConflictResolver
2122import com.google.android.fhir.sync.ResourceSyncException
23+ import com.google.android.fhir.sync.Result.Error
2224import com.google.android.fhir.sync.State
2325import com.google.android.fhir.sync.SyncJob
2426import com.google.android.fhir.sync.download.ResourceParamsBasedDownloadWorkManager
@@ -50,25 +52,16 @@ class SyncBroadcaster(
5052 val sharedSyncStatus : MutableSharedFlow <State > = MutableSharedFlow (),
5153 val dispatcherProvider : DispatcherProvider = DefaultDispatcherProvider ()
5254) {
53- fun runSync () {
55+ fun runSync (networkState : ( Context ) -> Boolean = { NetworkState (it).invoke() } ) {
5456 CoroutineScope (dispatcherProvider.io()).launch {
55- NetworkState (sharedPreferencesHelper.context).invoke( ).apply {
57+ networkState (sharedPreferencesHelper.context).apply {
5658 if (this ) onRunSync()
57- else
58- sharedSyncStatus.emit(
59- State .Failed (
60- com.google.android.fhir.sync.Result .Error (
61- listOf (
62- ResourceSyncException (
63- ResourceType .Flag ,
64- java.lang.Exception (
65- sharedPreferencesHelper.context.getString(R .string.unable_to_sync)
66- )
67- )
68- )
69- )
70- )
71- )
59+ else {
60+ val message = sharedPreferencesHelper.context.getString(R .string.unable_to_sync)
61+ val resourceSyncException =
62+ listOf (ResourceSyncException (ResourceType .Flag , java.lang.Exception (message)))
63+ sharedSyncStatus.emit(State .Failed (Error (resourceSyncException)))
64+ }
7265 }
7366 }
7467 }
Original file line number Diff line number Diff line change 1616
1717package org.smartregister.fhircore.engine.sync
1818
19- import android.app.Application
20- import androidx.test.core.app.ApplicationProvider
2119import io.mockk.every
2220import io.mockk.mockk
2321import io.mockk.verify
@@ -30,7 +28,6 @@ import org.smartregister.fhircore.engine.robolectric.RobolectricTest
3028class SyncBroadcasterTest : RobolectricTest () {
3129
3230 private lateinit var syncBroadcaster: SyncBroadcaster
33- private val context: Application = ApplicationProvider .getApplicationContext()
3431
3532 @Test
3633 fun runSync () {
You can’t perform that action at this time.
0 commit comments