I wanna test my Presenter
public class MainPresenter extends MvpBasePresenter<MainView> {
private Repository repository;
private final CompositeDisposable disposables = new CompositeDisposable();
public void setRepository(Repository repository) {
this.repository = repository;
}
public void loadFromRepository() {
getView().showLoading(false);
disposables.add(repository.getCountries()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribeWith(new DisposableObserver<List<Country>>() {
@Override
public void onNext(List<Country> countries) {
if (isViewAttached()) {
getView().setData(countries);
getView().showContent();
}
}
@Override
public void onError(Throwable e) {
if (isViewAttached()) {
getView().showError(e, false);
}
}
@Override
public void onComplete() {
}
}));
}
public void loadFromRemoteDatastore() {
disposables.add(new RemoteDataStore().getCountries()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribeWith(new DisposableObserver<List<Country>>() {
@Override
public void onNext(List<Country> countries) {
if (isViewAttached()) {
getView().setData(countries);
getView().showContent();
}
}
@Override
public void onError(Throwable e) {
if (isViewAttached()) {
getView().showError(e, false);
}
}
@Override
public void onComplete() {
}
}));
}
@Override
public void detachView(boolean retainInstance) {
super.detachView(retainInstance);
if (!retainInstance) {
disposables.clear();
}
}
}
However, I have many doubts, what's the best way to test it
1) Is this alright if I will write these 4 test scenarios
shouldShowContentWhenLoadFromRepository()
shouldShowErrorWhenLoadFromRepository()
shouldShowContentWhenLoadFromRemoteDatastore()
shouldShowErrorWhenLoadFromRemoteDatastore()
2) Should I write a test for detachView(boolean retainInstance) and clear disposables
3) What kind of mechanisms are the best in my case to test RxJava?