user info by MockK`() = runBlocking { } val fakeUser = User("Doe", 2L) val mockApiService = mockk<ApiService>(relaxed = true) every { mockApiService.getUser() } returns fakeUser val userRepository = UserRepository(mockApiService) userRepository.getUser().collect { assertEquals(it, fakeUser) }
lib ◦ And it was published as Turbine. • It is an extension function of Flow • Makes expressions more specific ◦ expectItem() ◦ expectError() ◦ expectComplete() • Takes advantage of Channels API and Coroutines API
execute it in your CallAdapterFactory. override fun adapt(call: Call<T>): Flow<Response<T>> = flow { val newCall = call.takeIf { !it.isExecuted } ?: call.clone() emit(newCall.awaitResponse()) }
a tool to transform stream types. • Apply flow to UI can actually be really convenient. ◦ View extensions (avoid quick clicks, text watchers, and so on) ◦ Use it with sealed classes. • Flow is simple.