Im trying to have a base class with a base traveler
but when I try to test if the function form that base traveler
was called it says that is not and then it says that there is!
open class BasePresenter<V : BaseView, T : BaseTraveler>() {
var view: V? = null
var traveler: T? = null
var userRepository: UserRepository? = null
val compositeSubscription = CompositeSubscription()
@CallSuper
open fun onCreate(view: V, traveler: T, userRepository: UserRepository) {
this.view = view
this.traveler = traveler
this.userRepository = userRepository
}
//...
}
class LoginPresenter : BasePresenter<LoginView, LoginTraveler>() {
override fun onCreate(view: LoginView, traveler: LoginTraveler, userRepository: UserRepository) {
super.onCreate(view, traveler, userRepository)
view.initViews()
}
fun onButtonLoginClick(username: String?, pwd: String?) {
if (fieldsAreInvalid(username, pwd)) {
return
}
view?.showProgressDialog()
userRepository?.login(username!!, pwd!!)
?.compose(Transformations.applyIoSchedulers<Session>())
?.subscribe({
view?.dismissLastProgressDialog()
traveler?.startLoggedViewWithCleanStack()
}, {
view?.dismissLastProgressDialog()
manageError(it, false)
})
?.followLifeCycle(this)
}
}
Test:
class LoginPresenterTest {
@Mock lateinit var view: LoginView
@Mock lateinit var traveler: LoginTraveler
@Mock lateinit var userRepository: UserRepository
lateinit var presenter: LoginPresenter
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
mockSchedulers()
presenter = LoginPresenter()
presenter.onCreate(view, traveler, userRepository)
reset(view)
}
@Test
fun test_onButtonLoginClick_ifSuccess_startMainView() {
val session = MockSession.session()
`when`(userRepository.login("clark", "123")).thenReturn(just(session))
presenter.onButtonLoginClick("clark", "123")
verify(view).showProgressDialog()
verify(view).dismissLastProgressDialog()
verify(traveler).startLoginViewWithCleanStack()
}
}
But I get Error:
Wanted but not invoked: traveler.startLoginViewWithCleanStack(); -> at LoginPresenterTest.test_onButtonLoginClick_ifSuccess_startMainView(LoginPresenterTest.kt:57)
However, there were other interactions with this mock: traveler.startLoggedViewWithCleanStack();
Why? Is it an inheritance problem?
Aucun commentaire:
Enregistrer un commentaire