savrov
06/13/2020, 5:36 PMoverride suspend fun create(item: Location): FlowResult<Location> {
val (base, version) = locationRepositoryMapper.map(item)
return locationRemoteSource.create(base, version)
.flatMapConcat {
when (it) {
is Result.Success -> {
locationLocalSource.create(
base = it.data.first,
version = it.data.second
)
}
else -> flowOf(it)
}
}.mapToModel()
}
The test itself:
@Test
fun `during creating, when data were saved into the remote source and failed to save it locally, then an error should be returned`() =
runTest {
// setup
coEvery { locationRemoteSource.create(any(), any()) } returns flowOf(Result.Success(locationPair))
coEvery { locationLocalSource.create(any(), any()) } returns flowOf(Result.Failure(mockk()))
coEvery { locationRepositoryMapper.map(any()) } returns locationPair
// invoke
val result = repository.create(mockk())
// verification
coVerify(exactly = 1) { locationRemoteSource.create(any(), any()) }
coVerify(exactly = 1) { locationLocalSource.create(any(), any()) }
// assertion
result.collect {
assertTrue(it.isFailure)
}
}
The problem that it fails on line:
coVerify(exactly = 1) { locationLocalSource.create(any(), any()) }
It prints out that locationLocalSource is not called
Verification failed: call 1 of 1: LocationLocalSource(#3).create(any(), any(), any())) was not called
I don’t know why it happens since according to my understanding if remote source returns success result, then create fun from local source should be called. Where im wrong? thank you in advance