// 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;
package com.tobi.movies.popularstream;




@RunWith(AndroidJUnit4.class)
public class PopularMoviesActivityTest {

    private static final long MOVIE_ID = 293660L;
    private static final String POSTER_PATH = "deadpool.jpg";
    private static final String MOVIE_TITLE = "Deadpool";
    private static final String MOVIE_DESCRIPTION = "Awesome movie";
    private static final String RELEASE_DATE = "2000-01-01";

    private ActivityTestRule<PopularMoviesActivity> rule;
    private ConfigurableBackend backend;
    private ApiMoviePoster apiMoviePoster;
    private ApiMovieDetails movieDetails;

    @Before
    public void setUp() throws Exception {
        MovieApplication movieApplication = (MovieApplication) InstrumentationRegistry.getTargetContext().getApplicationContext();
        backend = (ConfigurableBackend) ((TestPopularMoviesComponent) movieApplication.getPopularMoviesComponent()).backend();

        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
// 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;

package com.tobi.movies.popularstream;




@RunWith(AndroidJUnit4.class)
public class PopularMoviesActivityTest {

    private static final long MOVIE_ID = 293660L;
    private static final String POSTER_PATH = "deadpool.jpg";
    private static final String MOVIE_TITLE = "Deadpool";
    private static final String MOVIE_DESCRIPTION = "Awesome movie";
    private static final String RELEASE_DATE = "2000-01-01";

    private ActivityTestRule<PopularMoviesActivity> rule;
    private ConfigurableBackend backend;
    private ApiMoviePoster apiMoviePoster;
    private ApiMovieDetails movieDetails;

    @Before
    public void setUp() throws Exception {
        MovieApplication movieApplication = (MovieApplication) InstrumentationRegistry.getTargetContext().getApplicationContext();
        backend = (ConfigurableBackend) ((TestPopularMoviesComponent) movieApplication.getPopularMoviesComponent()).backend();

        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()