Skip to content

Commit

Permalink
remove roboelectric
Browse files Browse the repository at this point in the history
  • Loading branch information
esoxjem committed Oct 16, 2017
1 parent 7112aa8 commit c2e06dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,63 @@

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;

/**
* @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<Movie> movies)
{
if (isViewAttached())
{
private void onMovieFetchSuccess(List<Movie> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +31,7 @@
/**
* @author arunsasidharan
*/
@RunWith(RobolectricTestRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class MovieDetailsPresenterImplTest {
@Rule
public RxSchedulerRule rule;
Expand Down Expand Up @@ -88,8 +87,7 @@ public void shouldBeAbleToShowTrailers() {
TestScheduler testScheduler = new TestScheduler();
TestObserver<List<Video>> testObserver = new TestObserver<>();
Observable<List<Video>> responseObservable = Observable.just(videos)
.subscribeOn(testScheduler)
.observeOn(testScheduler);
.subscribeOn(testScheduler);
responseObservable.subscribe(testObserver);
when(movieDetailsInteractor.getTrailers(anyString())).thenReturn(responseObservable);

Expand All @@ -116,7 +114,7 @@ public void shouldBeAbleToShowReviews() {
TestObserver<List<Review>> testObserver = new TestObserver<>();
Observable<List<Review>> responseObservable = Observable.just(reviews)
.subscribeOn(testScheduler)
.observeOn(AndroidSchedulers.mainThread());
.observeOn(testScheduler);

responseObservable.subscribe(testObserver);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +24,7 @@
/**
* @author arunsasidharan
*/
@RunWith(RobolectricTestRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class MoviesListingPresenterImplTest {
@Rule
public RxSchedulerRule rule;
Expand All @@ -39,7 +39,6 @@ public class MoviesListingPresenterImplTest {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
presenter = new MoviesListingPresenterImpl(interactor);
}

Expand Down

0 comments on commit c2e06dd

Please sign in to comment.