### Question:
NewsViewModel extends ViewModel { public void fetchNews() { disposable.add(apiClient.fetchNews() .doOnEvent((newsList, throwable) -> onLoading()) .compose(rxSingleSchedulers.applySchedulers()) .subscribe(this::onSuccess, this::onError)); } @Inject  NewsViewModel(NewsApiClient apiClient, RxSingleSchedulers rxSingleSchedulers); MutableLiveData<NewsListViewState> getNewsListState(); void fetchNews();  }### Answer:
@Test public void testApiFetchDataSuccess() { when(apiClient.fetchNews()).thenReturn(Single.just(new NewsList())); viewModel.fetchNews(); verify(observer).onChanged(NewsListViewState.LOADING_STATE); verify(observer).onChanged(NewsListViewState.SUCCESS_STATE); }
@Test public void testApiFetchDataError() { when(apiClient.fetchNews()).thenReturn(Single.error(new Throwable("Api error"))); viewModel.fetchNews(); verify(observer).onChanged(NewsListViewState.LOADING_STATE); verify(observer).onChanged(NewsListViewState.ERROR_STATE); }