Skip to content

Instantly share code, notes, and snippets.

View Raiden18's full-sized avatar
🎯
Focusing

Paul Karpukhin Raiden18

🎯
Focusing
  • Limassol, Cyprus
View GitHub Profile
android {
packagingOptions {
merge 'META-INF/gradle/incremental.annotation.processors'
}
}
@IncrementalAnnotationProcessor(IncrementalAnnotationProcessorType.ISOLATING)
class YourProcessor1 : AbstractProcessor() {
// rest of the code
}
override fun getSupportedOptions(): Set<String> {
return listOf("org.gradle.annotation.processing.aggregating")
}
@Test
fun `Should show search button when internet connection is reappeared`() {
val testInternetConnectionEmitter = TestObservableEmitter(true)
val viewModel = ViewModelBuilder()
.withFilters(filters)
.withPriceNotifications(priceNotifications)
.withInternetConnectionStatusEmitter(testInternetConnectionEmitter)
.withIgnoringCallingStatesWithViewModelIsCreated()
.build()
@Test
fun `Should show search button when internet connection is reappeared`() {
val testInternetConnectionEmitter = TestObservableEmitter(true)
every { filtersInteractor.getFilters() } returns Single.just(filters)
every { priceNotificationsInteractor.getNotificationsFromInMemory() } returns Observable.just(priceNotifications)
every { networkConnectionChecker.isInternetAvailable() } returns Observable.create(testInternetConnectionEmitter)
val viewModel = createViewModel()
testScheduler.triggerActions()
clearMocks(screenState)
private inner class ViewModelBuilder {
fun withLoadingData(): ViewModelBuilder {
// For RxJava it would be every { someInteractor.loadSomething() } returns Single.never()
coEvery { someInteractor.loadSomething() } coAnswers {
delay(1_000)
"result is not important"
}
return this
}
@Test
fun `Should show content state if user clicks on retry button after loading data with error`() = runTest {
val throwable = Throwable()
val viewModel = ViewModelBuilder()
.withDataLoadedWithError(throwable)
.build(testScheduler)
//Replaced with Cases
Cases(viewModel)
internal inner class Cases(private val viewModel: SomeViewModel) {
fun nowDataIsLoadedSuccessfully(dataToLoad: String): Cases {
coEvery { someInteractor.loadSomething() } returns dataToLoad
return this
}
fun userClicksOnRetryButton(): Cases {
viewModel.onRetryButtonClicked()
return this
class SomeViewModelTest {
private val someInteractor: SomeInteractor = mockk(relaxed = true)
private val dataToLoad: String = "Data to load"
@Before
fun setUp() {
clearAllMocks()
}
class SomeViewModelTest {
private lateinit var someViewModel: SomeViewModel
private val someInteractor: SomeInteractor = mockk(relaxed = true)
private val dataToLoad: String = "Data to load"
@Before
fun setUp() {
clearAllMocks()
}