From dc9e34e7c5e5c774dd58773c294f36e3cf795aef Mon Sep 17 00:00:00 2001 From: andresmr Date: Tue, 16 Apr 2024 16:52:25 +0200 Subject: [PATCH] [ANDROAPP-5701] remove dispatcher io from viewmodelscope Signed-off-by: andresmr --- .../dhis2/utils/granularsync/GranularSyncPresenter.kt | 2 +- .../utils/granularsync/GranularSyncPresenterTest.kt | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/dhis2/utils/granularsync/GranularSyncPresenter.kt b/app/src/main/java/org/dhis2/utils/granularsync/GranularSyncPresenter.kt index 28d6b76b951..8b22365b852 100644 --- a/app/src/main/java/org/dhis2/utils/granularsync/GranularSyncPresenter.kt +++ b/app/src/main/java/org/dhis2/utils/granularsync/GranularSyncPresenter.kt @@ -429,7 +429,7 @@ class GranularSyncPresenter( } fun checkServerAvailability() { - viewModelScope.launch(dispatcher.io()) { + viewModelScope.launch { try { repository.checkServerAvailability() _serverAvailability.value = true diff --git a/app/src/test/java/org/dhis2/utils/granularsync/GranularSyncPresenterTest.kt b/app/src/test/java/org/dhis2/utils/granularsync/GranularSyncPresenterTest.kt index aed6ed2e9b5..9214df8b142 100644 --- a/app/src/test/java/org/dhis2/utils/granularsync/GranularSyncPresenterTest.kt +++ b/app/src/test/java/org/dhis2/utils/granularsync/GranularSyncPresenterTest.kt @@ -12,6 +12,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.resetMain +import kotlinx.coroutines.test.setMain import org.dhis2.commons.Constants import org.dhis2.commons.sync.ConflictType import org.dhis2.commons.sync.SyncContext @@ -55,8 +57,8 @@ class GranularSyncPresenterTest { private val trampolineSchedulerProvider = TrampolineSchedulerProvider() private val testingDispatcher = UnconfinedTestDispatcher() private val testDispatcher: DispatcherProvider = mock { - on { io() } doReturn Dispatchers.Unconfined - on { ui() } doReturn Dispatchers.Unconfined + on { io() } doReturn testingDispatcher + on { ui() } doReturn testingDispatcher } private val workManager = Mockito.mock(WorkManagerController::class.java) private val smsSyncProvider: SMSSyncProvider = mock() @@ -65,13 +67,12 @@ class GranularSyncPresenterTest { @Before fun setUp() { -// Dispatchers.setMain(testingDispatcher) + Dispatchers.setMain(testingDispatcher) } @After fun tearDown() { -// Dispatchers.resetMain() -// testDispatcher.cleanupTestCoroutines() + Dispatchers.resetMain() } @Test