diff --git a/app/build.gradle b/app/build.gradle index 8bb4b33b..79d4c6e3 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,7 +99,6 @@ dependencies { // Tests testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:2.9.0' - testCompile "org.robolectric:robolectric:3.4.2" androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) diff --git a/app/src/main/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImpl.java b/app/src/main/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImpl.java index 7c59949e..3e6d8bbc 100644 --- a/app/src/main/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImpl.java +++ b/app/src/main/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImpl.java @@ -53,7 +53,7 @@ private boolean isViewAttached() { public void showTrailers(Movie movie) { trailersSubscription = movieDetailsInteractor.getTrailers(movie.getId()) .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + .observeOn(Schedulers.trampoline()) .subscribe(this::onGetTrailersSuccess, t -> onGetTrailersFailure()); } @@ -70,7 +70,7 @@ private void onGetTrailersFailure() { @Override public void showReviews(Movie movie) { reviewSubscription = movieDetailsInteractor.getReviews(movie.getId()).subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + .observeOn(Schedulers.trampoline()) .subscribe(this::onGetReviewsSuccess, t -> onGetReviewsFailure()); } diff --git a/app/src/main/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImpl.java b/app/src/main/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImpl.java index 5d25ad2f..23aad0fc 100644 --- a/app/src/main/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImpl.java +++ b/app/src/main/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImpl.java @@ -2,7 +2,9 @@ import com.esoxjem.movieguide.Movie; import com.esoxjem.movieguide.util.RxUtils; + import java.util.List; + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; @@ -10,63 +12,53 @@ /** * @author arun */ -class MoviesListingPresenterImpl implements MoviesListingPresenter -{ +class MoviesListingPresenterImpl implements MoviesListingPresenter { private MoviesListingView view; private MoviesListingInteractor moviesInteractor; private Disposable fetchSubscription; - MoviesListingPresenterImpl(MoviesListingInteractor interactor) - { + MoviesListingPresenterImpl(MoviesListingInteractor interactor) { moviesInteractor = interactor; } @Override - public void setView(MoviesListingView view) - { + public void setView(MoviesListingView view) { this.view = view; displayMovies(); } @Override - public void destroy() - { + public void destroy() { view = null; RxUtils.unsubscribe(fetchSubscription); } @Override - public void displayMovies() - { + public void displayMovies() { showLoading(); - fetchSubscription = moviesInteractor.fetchMovies().subscribeOn(Schedulers.io()) + fetchSubscription = moviesInteractor.fetchMovies() + .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::onMovieFetchSuccess, this::onMovieFetchFailed); } - private void showLoading() - { - if (isViewAttached()) - { + private void showLoading() { + if (isViewAttached()) { view.loadingStarted(); } } - private void onMovieFetchSuccess(List movies) - { - if (isViewAttached()) - { + private void onMovieFetchSuccess(List movies) { + if (isViewAttached()) { view.showMovies(movies); } } - private void onMovieFetchFailed(Throwable e) - { + private void onMovieFetchFailed(Throwable e) { view.loadingFailed(e.getMessage()); } - private boolean isViewAttached() - { + private boolean isViewAttached() { return view != null; } } diff --git a/app/src/test/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImplTest.java b/app/src/test/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImplTest.java index 23feab52..c3279d07 100644 --- a/app/src/test/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImplTest.java +++ b/app/src/test/java/com/esoxjem/movieguide/details/MovieDetailsPresenterImplTest.java @@ -13,14 +13,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.List; import io.reactivex.Observable; -import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.TestScheduler; @@ -32,7 +31,7 @@ /** * @author arunsasidharan */ -@RunWith(RobolectricTestRunner.class) +@RunWith(MockitoJUnitRunner.class) public class MovieDetailsPresenterImplTest { @Rule public RxSchedulerRule rule; @@ -88,8 +87,7 @@ public void shouldBeAbleToShowTrailers() { TestScheduler testScheduler = new TestScheduler(); TestObserver> testObserver = new TestObserver<>(); Observable> responseObservable = Observable.just(videos) - .subscribeOn(testScheduler) - .observeOn(testScheduler); + .subscribeOn(testScheduler); responseObservable.subscribe(testObserver); when(movieDetailsInteractor.getTrailers(anyString())).thenReturn(responseObservable); @@ -116,7 +114,7 @@ public void shouldBeAbleToShowReviews() { TestObserver> testObserver = new TestObserver<>(); Observable> responseObservable = Observable.just(reviews) .subscribeOn(testScheduler) - .observeOn(AndroidSchedulers.mainThread()); + .observeOn(testScheduler); responseObservable.subscribe(testObserver); diff --git a/app/src/test/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImplTest.java b/app/src/test/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImplTest.java index e0e05f91..c9372e6b 100644 --- a/app/src/test/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImplTest.java +++ b/app/src/test/java/com/esoxjem/movieguide/listing/MoviesListingPresenterImplTest.java @@ -10,7 +10,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; @@ -24,7 +24,7 @@ /** * @author arunsasidharan */ -@RunWith(RobolectricTestRunner.class) +@RunWith(MockitoJUnitRunner.class) public class MoviesListingPresenterImplTest { @Rule public RxSchedulerRule rule; @@ -39,7 +39,6 @@ public class MoviesListingPresenterImplTest { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); presenter = new MoviesListingPresenterImpl(interactor); }