我一直在试图找到一种方法来测试我的存储库(我正在使用MVP),但是我花费了数小时试图弄清楚该如何做,您能帮我吗?
我能够调用方法searchBranchesInServer(),但无法进入onResponse()或onFailure()方法
@Override
public void searchBranchesInServer(String profileName, String repositoryName) {
Call<ArrayList<BranchesTagsResponse>> responseCall = mRest.create(RestRepository.class).listBranches(profileName, repositoryName);
responseCall.enqueue(new Callback<ArrayList<BranchesTagsResponse>>() {
@Override
public void onResponse(@NonNull Call<ArrayList<BranchesTagsResponse>> call, @NonNull Response<ArrayList<BranchesTagsResponse>> response) {
// call success method in presenter
}
@Override
public void onFailure(@NonNull Call<ArrayList<BranchesTagsResponse>> call, @NonNull Throwable t) {
// call error method in presenter
}
});
}
@Test
public void test1() {
String test = "ddd";
doAnswer(invocation -> {
BranchPresenter callback = (BranchPresenter) invocation.getArguments()[0];
callback.success(new ArrayList<>());
return null;
}).when(mModel).searchBranchesInServer(test, test);
mRepository.searchBranchesInServer(test, test);
}
你有什么主意吗?