aiidziis
04/01/2020, 9:16 AMcommonTest
?@Test
fun `When Error response, Completion must contain Error and Watcher must contain empty lists`() =
runTest {
if (isNative) return@runTest
selectNetwork.testCase = DashboardSelectTestCase.ERROR
val watcherMock = DashboardSectionsWatcherMock()
val completionMock = DashboardSectionsCompletionMock()
selectRepository.watchDashboardSections = watcherMock
selectRepository.startWatcher()
selectRepository.fetchDashboardSection("en_US", completionMock)
assertEquals(expected = DashboardSelectData.error, actual = completionMock.lastValue)
assertEquals(expected = mutableListOf(), actual = watcherMock.values)
}
fetchDashboardSection
is not a susped fun
because we plan to use this repository in iOS application, and afaik suspend
is not allowed in Kotlin Native.Thomas
04/01/2020, 11:08 AMsuspend fun
is allowed in Kotlin/Native. The issue is that it isn't added to the Objective C framework so you can't call it from Objective C or Swift code. As long as you only use this function in Kotlin code it is not an issue.aiidziis
04/01/2020, 11:12 AMsuspend fun
. Now I can test if I receive error, while performing fetch, but still can’t figure out how to test watchDashboardSection
invocation.localDataSource.selectAllSections()
.flowOn(Dispatchers.Default)
.map(::prepareDashboard)
.collect { watchDashboardSections?.invoke(it) }
Flow
and invoking callback with data.