这是我第一次将Mockito与Kotlin MVP Rx一起使用 而且,我收到一个错误“想要但不被调用-但是,与此模拟程序之间只有1次交互”
这里是我的主持人班
BirdCompare tester = new BirdCompare();
MathOperation addition = (a, b) -> (a + b);
MathOperation subtraction = (int a, int b) -> (a - b);
MathOperation multiplication = (int a, int b) -> {
return a * b;
};
MathOperation division = (a, b) -> a / b;
interface MathOperation {
int operation(int a, int b);
}
这是我的演示者视图
class MatchPresenter(private val matchContract: MatchContract,private val apiService: MatchService,private val appSchedulerProvider: AppSchedulerProvider) {
fun getLastMatch() {
apiService
.getLastMatches()
.subscribeOn(appSchedulerProvider.newThread())
.observeOn(appSchedulerProvider.ui())
.subscribe(
{ matchList ->
matchContract.onSuccess(matchList)
},
{ error ->
matchContract.onFailed(error.message)
}
)
}
fun getNextMatch() {
apiService
.getNextMatches()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ matchList ->
matchContract.onSuccess(matchList)
},
{ error ->
matchContract.onFailed(error.message)
}
)
}
} 这是我的AppSchedulerProvider 类AppSchedulerProvider:SchedulerProvider { 覆盖fun trampoline():Scheduler { TODO(“未实现”)//要更改已创建函数的主体,请使用File |设置|文件模板。 }
interface MatchContract {
fun onFailed(message: String?)
fun onSuccess(matchModel: MatchModel)
}
这里是我的presenterTest
override fun newThread(): Scheduler {
return Schedulers.newThread()
}
override fun ui(): Scheduler {
return AndroidSchedulers.mainThread()
}
override fun computation(): Scheduler {
return Schedulers.computation()
}
override fun io(): Scheduler {
return Schedulers.io()
}
}
答案 0 :(得分:0)
删除测试最后一行中view.onFailed的验证。除此之外,您所做的一切都正确。