// Path: app/src/main/java/com/daksh/tmdbsample/data/intdef/SortOrder.java
// public class SortOrder {
// 
//     public static final int POPULAR = 0;
//     public static final int TOP_RATED = 1;
// 
//     public final int value;
// 
//     public SortOrder(@SortOrderDef int value) {
//         this.value = value;
//     }
// 
//     @Retention(RetentionPolicy.SOURCE)
//     @IntDef({POPULAR, TOP_RATED})
//     public @interface SortOrderDef {}
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/model/MovieListApiResponse.java
// public class MovieListApiResponse {
// 
//     private final long page;
//     @SerializedName("results")
//     private final List<Movie> movies;
//     private final long totalResults;
//     private final long totalPages;
// 
//     public MovieListApiResponse(long page, List<Movie> movies, long totalResults, long totalPages) {
//         this.page = page;
//         this.movies = movies;
//         this.totalResults = totalResults;
//         this.totalPages = totalPages;
//     }
// 
//     public long getPage() {
//         return page;
//     }
// 
//     public List<Movie> getMovies() {
//         return movies;
//     }
// 
//     public long getTotalResults() {
//         return totalResults;
//     }
// 
//     public long getTotalPages() {
//         return totalPages;
//     }
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/source/local/AppSettings.java
// public interface AppSettings {
// 
//     SortOrder getSortOrder();
// 
//     void setSortOrder(SortOrder sortOrder);
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/source/remote/TmdbApi.java
// public interface TmdbApi {
// 
//     @GET("movie/popular")
//     Single<MovieListApiResponse> popular(@Query("page") Integer page);
// 
//     @GET("movie/top_rated")
//     Single<MovieListApiResponse> topRated(@Query("page") Integer page);
// 
//     @GET("search/movie/")
//     Single<MovieListApiResponse> search(@Query("query") String query, @Query("page") Integer page);
// }
// 
// Path: app/src/test/java/com/daksh/tmdbsample/di/TestInjector.java
// public enum TestInjector {
// 
//     INSTANCE;
// 
//     private TestAppComponent testAppComponent;
// 
//     public TestAppComponent initializeAppComponent(TestTmdbApplication application) {
//         testAppComponent = DaggerTestAppComponent.builder()
//                 .testAppModule(new TestAppModule(application))
//                 .networkModule(new NetworkModule(BuildConfig.BASE_URL, BuildConfig.API_KEY))
//                 .build();
// 
//         return testAppComponent;
//     }
// 
//     public TestAppComponent getAppComponent() {
//         return testAppComponent;
//     }
// }


import android.os.Build;
import com.daksh.tmdbsample.BuildConfig;
import com.daksh.tmdbsample.data.intdef.SortOrder;
import com.daksh.tmdbsample.data.model.MovieListApiResponse;
import com.daksh.tmdbsample.data.source.local.AppSettings;
import com.daksh.tmdbsample.data.source.remote.TmdbApi;
import com.daksh.tmdbsample.di.TestInjector;
import com.daksh.tmdbsample.util.MockResponse;
import com.google.gson.Gson;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import javax.inject.Inject;
import rx.Single;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
    @InjectMocks
    MovieListPresenter presenter;

    @Before
    public void setUp() {
        TestInjector.INSTANCE.getAppComponent().inject(this);
    }

    @After
    public void tearDown() {
        presenter.detachView();
    }

    @Test
    public void startPresenterWithPopularSortOrder() {
        when(appSettings.getSortOrder()).thenReturn(new SortOrder(SortOrder.POPULAR));

        MovieListApiResponse popularMovies = MockResponse.getPopularMovies(gson);

        when(api.popular(null))
                .thenReturn(Single.just(popularMovies));

        presenter.start();

        verify(api).popular(null);
        verify(view).showLoading();
    }

    @Test
    public void startPresenterWithTopRatedSortOrder() {
// Path: app/src/main/java/com/daksh/tmdbsample/data/intdef/SortOrder.java
// public class SortOrder {
// 
//     public static final int POPULAR = 0;
//     public static final int TOP_RATED = 1;
// 
//     public final int value;
// 
//     public SortOrder(@SortOrderDef int value) {
//         this.value = value;
//     }
// 
//     @Retention(RetentionPolicy.SOURCE)
//     @IntDef({POPULAR, TOP_RATED})
//     public @interface SortOrderDef {}
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/model/MovieListApiResponse.java
// public class MovieListApiResponse {
// 
//     private final long page;
//     @SerializedName("results")
//     private final List<Movie> movies;
//     private final long totalResults;
//     private final long totalPages;
// 
//     public MovieListApiResponse(long page, List<Movie> movies, long totalResults, long totalPages) {
//         this.page = page;
//         this.movies = movies;
//         this.totalResults = totalResults;
//         this.totalPages = totalPages;
//     }
// 
//     public long getPage() {
//         return page;
//     }
// 
//     public List<Movie> getMovies() {
//         return movies;
//     }
// 
//     public long getTotalResults() {
//         return totalResults;
//     }
// 
//     public long getTotalPages() {
//         return totalPages;
//     }
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/source/local/AppSettings.java
// public interface AppSettings {
// 
//     SortOrder getSortOrder();
// 
//     void setSortOrder(SortOrder sortOrder);
// }
// 
// Path: app/src/main/java/com/daksh/tmdbsample/data/source/remote/TmdbApi.java
// public interface TmdbApi {
// 
//     @GET("movie/popular")
//     Single<MovieListApiResponse> popular(@Query("page") Integer page);
// 
//     @GET("movie/top_rated")
//     Single<MovieListApiResponse> topRated(@Query("page") Integer page);
// 
//     @GET("search/movie/")
//     Single<MovieListApiResponse> search(@Query("query") String query, @Query("page") Integer page);
// }
// 
// Path: app/src/test/java/com/daksh/tmdbsample/di/TestInjector.java
// public enum TestInjector {
// 
//     INSTANCE;
// 
//     private TestAppComponent testAppComponent;
// 
//     public TestAppComponent initializeAppComponent(TestTmdbApplication application) {
//         testAppComponent = DaggerTestAppComponent.builder()
//                 .testAppModule(new TestAppModule(application))
//                 .networkModule(new NetworkModule(BuildConfig.BASE_URL, BuildConfig.API_KEY))
//                 .build();
// 
//         return testAppComponent;
//     }
// 
//     public TestAppComponent getAppComponent() {
//         return testAppComponent;
//     }
// }


// Path: app/src/test/java/com/daksh/tmdbsample/movielist/MovieListPresenterTest.java
import android.os.Build;
import com.daksh.tmdbsample.BuildConfig;
import com.daksh.tmdbsample.data.intdef.SortOrder;
import com.daksh.tmdbsample.data.model.MovieListApiResponse;
import com.daksh.tmdbsample.data.source.local.AppSettings;
import com.daksh.tmdbsample.data.source.remote.TmdbApi;
import com.daksh.tmdbsample.di.TestInjector;
import com.daksh.tmdbsample.util.MockResponse;
import com.google.gson.Gson;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import javax.inject.Inject;
import rx.Single;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

    @InjectMocks
    MovieListPresenter presenter;

    @Before
    public void setUp() {
        TestInjector.INSTANCE.getAppComponent().inject(this);
    }

    @After
    public void tearDown() {
        presenter.detachView();
    }

    @Test
    public void startPresenterWithPopularSortOrder() {
        when(appSettings.getSortOrder()).thenReturn(new SortOrder(SortOrder.POPULAR));

        MovieListApiResponse popularMovies = MockResponse.getPopularMovies(gson);

        when(api.popular(null))
                .thenReturn(Single.just(popularMovies));

        presenter.start();

        verify(api).popular(null);
        verify(view).showLoading();
    }

    @Test
    public void startPresenterWithTopRatedSortOrder() {
        when(appSettings.getSortOrder()).thenReturn(new SortOrder(SortOrder.TOP_RATED));