使用Junit Mockito测试以下方法。如何测试onSuccess方法?

时间:2019-03-18 16:38:32

标签: android mockito rx-java powermockito

public void loadStore(){

   getStoreUseCase.execute()
            .subscribe(new Subscriber<Store>() {
                @Override
                public void onSuccess(Store store) {

                }

                @Override
                public void onError(Throwable throwable) {
                    super.onError(throwable);

                    }
                }

                @Override
                public void onUnauthorized(Throwable throwable) {

                }
            });
}

GetStoreUseCase如下:

公共类GetStoreUseCase扩展了AbstractUseCase {

private Throwable mException = new Exception();

@Override
public Observable<Store> buildUseCase() {

    mGlhManager = new GlhApiManager();


        mWalkId = mGlhManager
                .createStore(SessionData.getInstance().getConfiguration().getLocationId())
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .onErrorReturn(new Func1<Throwable, StoreWalk>() {
                    @Override
                    public Store call(Throwable throwable) {
                        mException = throwable;
                        return new Store();
                    }
                })
                .toBlocking()
                .first()
                .getWalkId();
    }

    if (mWalkId == null) {
        return Observable.error(mException);
    }


    return mGlhManager
            .getStoreWalkWithParameters(mLocation, mWalkId, mFieldParameters);
}

}

我总是收到订户的OnError和nullPointer异常。如何测试OnSuccess方法?

0 个答案:

没有答案