@Test public void errorViewIsShownWhenGetMovieDetailsGivesError() { when(mMovieRepository.getMovieDetails(MOVIE_ID)).thenReturn( Observable.<Movie>error(new Throwable("Exception"))); mDetailsViewModel.getMovieDetails(MOVIE_ID); assertTrue(mDetailsViewModel.errorViewShowing.get()); assertFalse(mDetailsViewModel.isMovieLoading.get()); }
public void getMovieDetails(long movieId) { isMovieLoading.set(true); errorViewShowing.set(false); mMoviesRepository.getMovieDetails(movieId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Movie>() { @Override public void onNext(Movie value) { setMovie(value); } @Override public void onError(Throwable e) { errorViewShowing.set(true); isMovieLoading.set(false); } @Override public void onComplete() { isMovieLoading.set(false); errorViewShowing.set(false); } }); }
MovieDetailsViewModel extends MovieViewModel { public void getMovieDetails(long movieId) { isMovieLoading.set(true); errorViewShowing.set(false); mMoviesRepository.getMovieDetails(movieId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Movie>() { @Override public void onNext(Movie value) { setMovie(value); } @Override public void onError(Throwable e) { errorViewShowing.set(true); isMovieLoading.set(false); } @Override public void onComplete() { isMovieLoading.set(false); errorViewShowing.set(false); } }); } }
MovieDetailsViewModel extends MovieViewModel { public void getMovieDetails(long movieId) { isMovieLoading.set(true); errorViewShowing.set(false); mMoviesRepository.getMovieDetails(movieId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Movie>() { @Override public void onNext(Movie value) { setMovie(value); } @Override public void onError(Throwable e) { errorViewShowing.set(true); isMovieLoading.set(false); } @Override public void onComplete() { isMovieLoading.set(false); errorViewShowing.set(false); } }); } MovieDetailsViewModel(MoviesRepository moviesRepository); }
MovieDetailsViewModel extends MovieViewModel { public void getMovieDetails(long movieId) { isMovieLoading.set(true); errorViewShowing.set(false); mMoviesRepository.getMovieDetails(movieId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Movie>() { @Override public void onNext(Movie value) { setMovie(value); } @Override public void onError(Throwable e) { errorViewShowing.set(true); isMovieLoading.set(false); } @Override public void onComplete() { isMovieLoading.set(false); errorViewShowing.set(false); } }); } MovieDetailsViewModel(MoviesRepository moviesRepository); void getMovieDetails(long movieId); }
MovieDetailsViewModel extends MovieViewModel { public void getMovieDetails(long movieId) { isMovieLoading.set(true); errorViewShowing.set(false); mMoviesRepository.getMovieDetails(movieId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Movie>() { @Override public void onNext(Movie value) { setMovie(value); } @Override public void onError(Throwable e) { errorViewShowing.set(true); isMovieLoading.set(false); } @Override public void onComplete() { isMovieLoading.set(false); errorViewShowing.set(false); } }); } MovieDetailsViewModel(MoviesRepository moviesRepository); void getMovieDetails(long movieId); final ObservableBoolean isMovieLoading; final ObservableBoolean errorViewShowing; final ObservableField<String> errorString; }