package com.tobi.movies.posterdetails;

import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.tobi.movies.EspressoDependencies;
import com.tobi.movies.MovieApplication;
import com.tobi.movies.backend.ConfigurableBackend;
import com.tobi.movies.utils.MovieRobot;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MovieDetailsActivityTest {

    private static final long MOVIE_ID = 293660L;
    private static final String MOVIE_TITLE = "Deadpool";
    private static final String MOVIE_DESCRIPTION = "Such an awesome movie!";
    private static final String POSTER_PATH = "deadpool.jpg";

    private ConfigurableBackend backend = new ConfigurableBackend();

    private ActivityTestRule<MovieDetailsActivity> rule = new ActivityTestRule<MovieDetailsActivity>(MovieDetailsActivity.class) {
        @Override
        protected void beforeActivityLaunched() {
            MovieApplication movieApplication = (MovieApplication) InstrumentationRegistry.getTargetContext().getApplicationContext();
            movieApplication.setDependencies(new EspressoDependencies(backend));
        }
    };

    @Test
    public void shouldShowMovieTitle() throws Exception {
        ApiMovieDetails apiMovieDetails = createApiMovieDetails(MOVIE_ID, MOVIE_TITLE, MOVIE_DESCRIPTION, POSTER_PATH);

        MovieRobot
                .createRobot(backend, rule)
                .addRemoteMovieDetails(apiMovieDetails)
                .launchDetailsScreen(MOVIE_ID)
                .checkMovieTitleIsDisplayed(MOVIE_TITLE)
                .checkMovieDescriptionIsDisplayed(MOVIE_DESCRIPTION);
    }

    private ApiMovieDetails createApiMovieDetails(long movieId, String movieTitle, String movieOverview, String posterPath) {
        ApiMovieDetails apiMovieDetails = new ApiMovieDetails();
        apiMovieDetails.originalTitle = movieTitle;
        apiMovieDetails.movieId = movieId;
        apiMovieDetails.overview = movieOverview;
        apiMovieDetails.posterPath = posterPath;

        return apiMovieDetails;
    }
}

@@ -368,16 +368,41 @@
 Robot;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -1276,55 +1276,87 @@
  %7D;%0A
-%0A    @Test%0A    public void shouldShowMovieTitle
+    private ApiMovieDetails apiMovieDetails;%0A%0A    @Before%0A    public void setUp
 () t
@@ -1381,32 +1381,16 @@
         
-ApiMovieDetails 
 apiMovie
@@ -1477,16 +1477,90 @@
 _PATH);%0A
+    %7D%0A%0A    @Test%0A    public void shouldShowMovieTitle() throws Exception %7B
 %0A       

Create ApiMovieDetails in setup in order to have a clean test