// Path: app/src/main/java/com/tobi/movies/MovieApplication.java
// public class MovieApplication extends Application {
// 
//     private PopularMoviesComponent popularMoviesComponent;
//     private MovieDetailsComponent movieDetailsComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ApplicationComponent applicationComponent = applicationComponent();
//         popularMoviesComponent = popularMoviesComponent(applicationComponent);
//         movieDetailsComponent = movieDetailsComponent(applicationComponent);
//     }
// 
//     protected ApplicationComponent applicationComponent() {
//         return DaggerApplicationComponent.create();
//     }
// 
//     protected MovieDetailsComponent movieDetailsComponent(ApplicationComponent applicationComponent) {
//         return DaggerMovieDetailsComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     protected PopularMoviesComponent popularMoviesComponent(ApplicationComponent applicationComponent) {
//         return DaggerPopularMoviesComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     public PopularMoviesComponent getPopularMoviesComponent() {
//         return popularMoviesComponent;
//     }
// 
//     public MovieDetailsComponent getMovieDetailsComponent() {
//         return movieDetailsComponent;
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/backend/ConfigurableBackend.java
// public class ConfigurableBackend implements Backend {
// 
//     private final Map<Long, ApiMovieDetails> movieDetails = new HashMap<>();
//     private final List<ApiMoviePoster> popularStream = Lists.newArrayList();
// 
//     public void addMovieDetails(ApiMovieDetails apiMovieDetails) {
//         movieDetails.put(apiMovieDetails.movieId, apiMovieDetails);
//     }
// 
//     public void addToPopularStream(ApiMoviePoster movieDetails) {
//         popularStream.add(movieDetails);
//     }
// 
//     @Override
//     public Observable<ApiPopularMoviesResponse> popularStream() {
//         return Observable.fromCallable(new Callable<ApiPopularMoviesResponse>() {
//             @Override
//             public ApiPopularMoviesResponse call() throws Exception {
//                 return new PublicApiPopularMoviesResponse(popularStream);
//             }
//         });
//     }
// 
//     @Override
//     public Observable<ApiMovieDetails> movieDetails(@Path("id") final long movieId) {
//         return Observable.fromCallable(new Callable<ApiMovieDetails>() {
//             @Override
//             public ApiMovieDetails call() throws Exception {
//                 return movieDetails.get(movieId);
//             }
//         });
//     }
// 
//     public void clear() {
//         movieDetails.clear();
//         popularStream.clear();
//     }
// }
// 
// Path: base/src/main/java/com/tobi/movies/posterdetails/ApiMovieDetails.java
// public class ApiMovieDetails {
// 
//     @SerializedName("id")
//     public long movieId;
// 
//     @SerializedName("poster_path")
//     public String posterPath;
// 
//     @SerializedName("original_title")
//     public String originalTitle;
// 
//     @SerializedName("overview")
//     public String overview;
// 
//     @SerializedName("release_date")
//     public String releaseDate;
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/posterdetails/PosterDetailsRobot.java
// public class PosterDetailsRobot extends Robot<PosterDetailsRobot> {
// 
//     public static PosterDetailsRobot create() {
//         return new PosterDetailsRobot();
//     }
// 
//     public PosterDetailsRobot() {
//     }
// 
//     public PosterDetailsRobot checkMovieTitleIsDisplayed(String movieTitle) {
//         return checkTextIsDisplayed(movieTitle, R.id.movieTitle);
//     }
// 
//     public PosterDetailsRobot launchDetailsScreen(long movieId, ActivityTestRule<MovieDetailsActivity> testRule) {
//         testRule.launchActivity(MovieDetailsActivity.createIntentFor(movieId, InstrumentationRegistry.getInstrumentation()
//                 .getTargetContext()
//                 .getApplicationContext()));
//         return new PosterDetailsRobot();
//     }
// 
//     public PosterDetailsRobot checkMovieDescriptionIsDisplayed(String movieDescription) {
//         return checkTextIsDisplayed(movieDescription, R.id.movieOverview);
//     }
// }


import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.tobi.movies.MovieApplication;
import com.tobi.movies.backend.ConfigurableBackend;
import com.tobi.movies.posterdetails.ApiMovieDetails;
import com.tobi.movies.posterdetails.PosterDetailsRobot;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
        rule = new ActivityTestRule<>(PopularMoviesActivity.class);

        apiMoviePoster = createApiMoviePoster(MOVIE_ID, POSTER_PATH);
        movieDetails = createMovieDetails(MOVIE_ID, MOVIE_TITLE, MOVIE_DESCRIPTION, POSTER_PATH, RELEASE_DATE);
    }

    @After
    public void tearDown() throws Exception {
        backend.clear();
    }

    @Test
    public void shouldShowPoster() throws Exception {
        backend.addToPopularStream(apiMoviePoster);

        PopularMoviesRobot
                .create()
                .launchPopularMovies(rule)
                .checkPosterWithPathIsDisplayedAtPosition(0, POSTER_PATH);
    }

    @Test
    public void shouldNavigateToMovieDetails() throws Exception {
        backend.addToPopularStream(apiMoviePoster);
        backend.addMovieDetails(movieDetails);

        PopularMoviesRobot
                .create()
                .launchPopularMovies(rule)
                .selectPosterAtPosition(0)
// Path: app/src/main/java/com/tobi/movies/MovieApplication.java
// public class MovieApplication extends Application {
// 
//     private PopularMoviesComponent popularMoviesComponent;
//     private MovieDetailsComponent movieDetailsComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ApplicationComponent applicationComponent = applicationComponent();
//         popularMoviesComponent = popularMoviesComponent(applicationComponent);
//         movieDetailsComponent = movieDetailsComponent(applicationComponent);
//     }
// 
//     protected ApplicationComponent applicationComponent() {
//         return DaggerApplicationComponent.create();
//     }
// 
//     protected MovieDetailsComponent movieDetailsComponent(ApplicationComponent applicationComponent) {
//         return DaggerMovieDetailsComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     protected PopularMoviesComponent popularMoviesComponent(ApplicationComponent applicationComponent) {
//         return DaggerPopularMoviesComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     public PopularMoviesComponent getPopularMoviesComponent() {
//         return popularMoviesComponent;
//     }
// 
//     public MovieDetailsComponent getMovieDetailsComponent() {
//         return movieDetailsComponent;
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/backend/ConfigurableBackend.java
// public class ConfigurableBackend implements Backend {
// 
//     private final Map<Long, ApiMovieDetails> movieDetails = new HashMap<>();
//     private final List<ApiMoviePoster> popularStream = Lists.newArrayList();
// 
//     public void addMovieDetails(ApiMovieDetails apiMovieDetails) {
//         movieDetails.put(apiMovieDetails.movieId, apiMovieDetails);
//     }
// 
//     public void addToPopularStream(ApiMoviePoster movieDetails) {
//         popularStream.add(movieDetails);
//     }
// 
//     @Override
//     public Observable<ApiPopularMoviesResponse> popularStream() {
//         return Observable.fromCallable(new Callable<ApiPopularMoviesResponse>() {
//             @Override
//             public ApiPopularMoviesResponse call() throws Exception {
//                 return new PublicApiPopularMoviesResponse(popularStream);
//             }
//         });
//     }
// 
//     @Override
//     public Observable<ApiMovieDetails> movieDetails(@Path("id") final long movieId) {
//         return Observable.fromCallable(new Callable<ApiMovieDetails>() {
//             @Override
//             public ApiMovieDetails call() throws Exception {
//                 return movieDetails.get(movieId);
//             }
//         });
//     }
// 
//     public void clear() {
//         movieDetails.clear();
//         popularStream.clear();
//     }
// }
// 
// Path: base/src/main/java/com/tobi/movies/posterdetails/ApiMovieDetails.java
// public class ApiMovieDetails {
// 
//     @SerializedName("id")
//     public long movieId;
// 
//     @SerializedName("poster_path")
//     public String posterPath;
// 
//     @SerializedName("original_title")
//     public String originalTitle;
// 
//     @SerializedName("overview")
//     public String overview;
// 
//     @SerializedName("release_date")
//     public String releaseDate;
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/posterdetails/PosterDetailsRobot.java
// public class PosterDetailsRobot extends Robot<PosterDetailsRobot> {
// 
//     public static PosterDetailsRobot create() {
//         return new PosterDetailsRobot();
//     }
// 
//     public PosterDetailsRobot() {
//     }
// 
//     public PosterDetailsRobot checkMovieTitleIsDisplayed(String movieTitle) {
//         return checkTextIsDisplayed(movieTitle, R.id.movieTitle);
//     }
// 
//     public PosterDetailsRobot launchDetailsScreen(long movieId, ActivityTestRule<MovieDetailsActivity> testRule) {
//         testRule.launchActivity(MovieDetailsActivity.createIntentFor(movieId, InstrumentationRegistry.getInstrumentation()
//                 .getTargetContext()
//                 .getApplicationContext()));
//         return new PosterDetailsRobot();
//     }
// 
//     public PosterDetailsRobot checkMovieDescriptionIsDisplayed(String movieDescription) {
//         return checkTextIsDisplayed(movieDescription, R.id.movieOverview);
//     }
// }


// Path: app/src/androidTest/java/com/tobi/movies/popularstream/PopularMoviesActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.tobi.movies.MovieApplication;
import com.tobi.movies.backend.ConfigurableBackend;
import com.tobi.movies.posterdetails.ApiMovieDetails;
import com.tobi.movies.posterdetails.PosterDetailsRobot;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

        rule = new ActivityTestRule<>(PopularMoviesActivity.class);

        apiMoviePoster = createApiMoviePoster(MOVIE_ID, POSTER_PATH);
        movieDetails = createMovieDetails(MOVIE_ID, MOVIE_TITLE, MOVIE_DESCRIPTION, POSTER_PATH, RELEASE_DATE);
    }

    @After
    public void tearDown() throws Exception {
        backend.clear();
    }

    @Test
    public void shouldShowPoster() throws Exception {
        backend.addToPopularStream(apiMoviePoster);

        PopularMoviesRobot
                .create()
                .launchPopularMovies(rule)
                .checkPosterWithPathIsDisplayedAtPosition(0, POSTER_PATH);
    }

    @Test
    public void shouldNavigateToMovieDetails() throws Exception {
        backend.addToPopularStream(apiMoviePoster);
        backend.addMovieDetails(movieDetails);

        PopularMoviesRobot
                .create()
                .launchPopularMovies(rule)
                .selectPosterAtPosition(0)
                .toRobot(PosterDetailsRobot.class)