Open
Description
I have the following test:
private var interceptSelectedRoute = mock<InterceptSelectedRoute>()
@Captor
val interceptSelectedRouteCaptor = argumentCaptor<DisposableObserver<DetailedRoute>>()
@Test
fun `when selected route is intercepted, we should start persisting it`() {
doNothing().`when`(interceptSelectedRoute).dispose()
interactor.start()
val selectedRoute = NavigatorRouteFactory.makeDetailedRoute()
verify(interceptSelectedRoute).execute(interceptSelectedRouteCaptor.capture(), eq(null))
interceptSelectedRouteCaptor.firstValue.onNext(selectedRoute)
assertEquals(
expected = NavigatorStateMachine.State.Initialization.PersistingRoute(selectedRoute),
actual = interactor.stateMachine.state
)
}
Inside interactor
there is this method invocation:
private fun stopInterceptingSelectedRoute() {
interceptSelectedRoute.dispose()
}
interceptSelectedRoute
is a child of the following class:
abstract class ObservableUseCase<T, in Params> constructor(
private val postExecutionThread: PostExecutionThread
) {
val subscriptions = CompositeDisposable()
abstract fun buildUseCaseObservable(params: Params? = null): Observable<T>
open fun execute(observer: DisposableObserver<T>, params: Params? = null) {
val observable = this.buildUseCaseObservable(params)
.subscribeOn(Schedulers.io())
.observeOn(postExecutionThread.scheduler)
observable.subscribeWith(observer).disposedBy(subscriptions)
}
fun dispose() {
subscriptions.clear()
}
}
When stopInterceptingSelectedRoute()
is invoked, I get NullPointerException
because subscriptions == null
.
I don't understand why doNothing()
does not work here as expected (meaning that the real method is not invoked). Could you help?