My project uses clean architecture.
I use:
- MVP for the presentation layer
- UseCases that use RxAndroid and get DisposableObservers
- Dagger 2 for DI
Sample code from a presenter (Kotlin):
fun doSomething() {
getInterestingDataUseCase.execute(object : DisposableObserver<List<InterestingDataItem>>() {
override fun onStart() {
view.showLoadingIndicator()
}
override fun onNext(dataList: List<InterestingDataItem>) {
view.showDataItems(dataList)
}
override fun onError(e: Throwable) {
view.showErrorDialog()
}
override fun onComplete() {
view.hideLoadingIndicator()
}
})
}
I want to write unit tests for this presenter.
My question is: Are the different method calls in the DisposableObserver worth testing (onStart, onNext...)? And if they are, it looks like I would need to inject the DisposableObserver into the presenter(so that I will be able to mock it). Is there a cleaner way?
Eventually I got to this solution:
Example for a test that checks that the view hides its progress indicator when a request is complete: