@Test public void getPopularMoviesReturnsEmptyList() { when(mMoviesRepository.getPopularMovies(PAGE)).thenReturn(Observable.just(EMPTY_MOVIES)); mMoviesViewModel.discoverMovies(true); verify(mMoviesRepository).getPopularMovies(PAGE); assertTrue(mMoviesViewModel.emptyViewShowing.get()); assertFalse(mMoviesViewModel.moviesLoading.get()); assertFalse(mMoviesViewModel.errorViewShowing.get()); }
public void discoverMovies(boolean showLoading) { moviesLoading.set(showLoading); errorViewShowing.set(false); emptyViewShowing.set(false); mMoviesRepository.getPopularMovies(1) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Movie>>() { @Override public void onNext(List<Movie> value) { boolean isEmpty = value == null || value.isEmpty(); if (!isEmpty) { movies.clear(); movies.addAll(value); } emptyViewShowing.set(isEmpty); } @Override public void onError(Throwable throwable) { errorViewShowing.set(true); moviesLoading.set(false); emptyViewShowing.set(false); errorString.set(getErrorMessage(throwable)); } @Override public void onComplete() { moviesLoading.set(false); errorViewShowing.set(false); } }); }
MoviesViewModel extends BaseObservable { public void discoverMovies(boolean showLoading) { moviesLoading.set(showLoading); errorViewShowing.set(false); emptyViewShowing.set(false); mMoviesRepository.getPopularMovies(1) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Movie>>() { @Override public void onNext(List<Movie> value) { boolean isEmpty = value == null || value.isEmpty(); if (!isEmpty) { movies.clear(); movies.addAll(value); } emptyViewShowing.set(isEmpty); } @Override public void onError(Throwable throwable) { errorViewShowing.set(true); moviesLoading.set(false); emptyViewShowing.set(false); errorString.set(getErrorMessage(throwable)); } @Override public void onComplete() { moviesLoading.set(false); errorViewShowing.set(false); } }); } }
MoviesViewModel extends BaseObservable { public void discoverMovies(boolean showLoading) { moviesLoading.set(showLoading); errorViewShowing.set(false); emptyViewShowing.set(false); mMoviesRepository.getPopularMovies(1) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Movie>>() { @Override public void onNext(List<Movie> value) { boolean isEmpty = value == null || value.isEmpty(); if (!isEmpty) { movies.clear(); movies.addAll(value); } emptyViewShowing.set(isEmpty); } @Override public void onError(Throwable throwable) { errorViewShowing.set(true); moviesLoading.set(false); emptyViewShowing.set(false); errorString.set(getErrorMessage(throwable)); } @Override public void onComplete() { moviesLoading.set(false); errorViewShowing.set(false); } }); } MoviesViewModel(@NonNull Context context, @NonNull MoviesRepository moviesRepository); }
MoviesViewModel extends BaseObservable { public void discoverMovies(boolean showLoading) { moviesLoading.set(showLoading); errorViewShowing.set(false); emptyViewShowing.set(false); mMoviesRepository.getPopularMovies(1) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Movie>>() { @Override public void onNext(List<Movie> value) { boolean isEmpty = value == null || value.isEmpty(); if (!isEmpty) { movies.clear(); movies.addAll(value); } emptyViewShowing.set(isEmpty); } @Override public void onError(Throwable throwable) { errorViewShowing.set(true); moviesLoading.set(false); emptyViewShowing.set(false); errorString.set(getErrorMessage(throwable)); } @Override public void onComplete() { moviesLoading.set(false); errorViewShowing.set(false); } }); } MoviesViewModel(@NonNull Context context, @NonNull MoviesRepository moviesRepository); void start(); void discoverMovies(boolean showLoading); }
MoviesViewModel extends BaseObservable { public void discoverMovies(boolean showLoading) { moviesLoading.set(showLoading); errorViewShowing.set(false); emptyViewShowing.set(false); mMoviesRepository.getPopularMovies(1) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Movie>>() { @Override public void onNext(List<Movie> value) { boolean isEmpty = value == null || value.isEmpty(); if (!isEmpty) { movies.clear(); movies.addAll(value); } emptyViewShowing.set(isEmpty); } @Override public void onError(Throwable throwable) { errorViewShowing.set(true); moviesLoading.set(false); emptyViewShowing.set(false); errorString.set(getErrorMessage(throwable)); } @Override public void onComplete() { moviesLoading.set(false); errorViewShowing.set(false); } }); } MoviesViewModel(@NonNull Context context, @NonNull MoviesRepository moviesRepository); void start(); void discoverMovies(boolean showLoading); final ObservableList<Movie> movies; final ObservableBoolean moviesLoading; final ObservableBoolean emptyViewShowing; final ObservableBoolean errorViewShowing; final ObservableField<String> errorString; }