Skip to content

Commit 5b6ee66

Browse files
Merge branch 'master' into coroutines_course_empty_exercises
2 parents df6c448 + a77fb71 commit 5b6ee66

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

app/src/test/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase10/CalculationInBackgroundViewModelTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.lukaslechner.coroutineusecasesonandroid.usecases.coroutines.usecase1
33
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
44
import com.lukaslechner.coroutineusecasesonandroid.utils.ReplaceMainDispatcherRule
55
import kotlinx.coroutines.test.StandardTestDispatcher
6+
import kotlinx.coroutines.test.UnconfinedTestDispatcher
7+
import kotlinx.coroutines.test.advanceTimeBy
68
import kotlinx.coroutines.test.runCurrent
79
import kotlinx.coroutines.test.runTest
810
import org.junit.Assert
@@ -22,15 +24,16 @@ class CalculationInBackgroundViewModelTest {
2224

2325
@Test
2426
fun `performCalculation() should perform correct calculations`() = runTest {
27+
28+
val testDispatcher = UnconfinedTestDispatcher(testScheduler)
2529
val viewModel =
26-
CalculationInBackgroundViewModel(StandardTestDispatcher(testScheduler)).apply {
30+
CalculationInBackgroundViewModel(testDispatcher).apply {
2731
observe()
2832
}
2933

3034
Assert.assertTrue(receivedUiStates.isEmpty())
3135

3236
viewModel.performCalculation(1)
33-
runCurrent()
3437

3538
Assert.assertEquals(
3639
UiState.Loading,
@@ -45,7 +48,6 @@ class CalculationInBackgroundViewModelTest {
4548
receivedUiStates.clear()
4649

4750
viewModel.performCalculation(2)
48-
runCurrent()
4951

5052
Assert.assertEquals(
5153
UiState.Loading,
@@ -60,7 +62,6 @@ class CalculationInBackgroundViewModelTest {
6062
receivedUiStates.clear()
6163

6264
viewModel.performCalculation(3)
63-
runCurrent()
6465

6566
Assert.assertEquals(
6667
UiState.Loading,

0 commit comments

Comments
 (0)