// Path: app/src/androidTest/java/com/tobi/movies/Robot.java
// public abstract class Robot<T extends Robot> {
// 
//     protected T checkTextIsDisplayed(String text, @IdRes int view) {
//         onView(allOf(withId(view), withText(text))).check(matches(isDisplayed()));
//         return (T) this;
//     }
// 
//     protected T selectPositionInRecyclerView(int position, @IdRes int recyclerView) {
//         onView(withId(recyclerView))
//                 .perform(RecyclerViewActions.actionOnItemAtPosition(position, click()));
//         return (T) this;
//     }
// 
//     public T waitFor(int seconds) throws InterruptedException {
//         Thread.sleep(seconds * 1000);
//         return (T) this;
//     }
// 
// 
//     public <K> K toRobot(Class<K> robotClass) throws IllegalAccessException, InstantiationException {
//         return robotClass.newInstance();
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/matchers/PosterMatcher.java
// public class PosterMatcher {
// 
//     public static Matcher<? super View> hasPosterAt(final int position, final String posterPath) {
//         return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
//             @Override
//             public void describeTo(Description description) {
//                 description.appendText("has poster with path:" + posterPath + " at position:" + position);
//             }
// 
//             @Override
//             protected boolean matchesSafely(RecyclerView item) {
//                 MoviePosterAdapter adapter = (MoviePosterAdapter) item.getAdapter();
//                 MoviePoster moviePoster = adapter.getItemAt(position);
//                 return moviePoster.getPosterPath().contains(posterPath);
//             }
//         };
//     }
// }


import android.support.test.rule.ActivityTestRule;
import com.tobi.movies.R;
import com.tobi.movies.Robot;
import com.tobi.movies.matchers.PosterMatcher;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
package com.tobi.movies.popularstream;




public class PopularMoviesRobot extends Robot<PopularMoviesRobot> {

    public static PopularMoviesRobot create() {
        return new PopularMoviesRobot();
    }

    public PopularMoviesRobot() {
    }

    public PopularMoviesRobot launchPopularMovies(ActivityTestRule<PopularMoviesActivity> rule) {
        rule.launchActivity(null);
        return this;
    }

    public PopularMoviesRobot checkPosterWithPathIsDisplayedAtPosition(int position, String posterPath) {
        onView(withId(R.id.popularMovies_recycler))
// Path: app/src/androidTest/java/com/tobi/movies/Robot.java
// public abstract class Robot<T extends Robot> {
// 
//     protected T checkTextIsDisplayed(String text, @IdRes int view) {
//         onView(allOf(withId(view), withText(text))).check(matches(isDisplayed()));
//         return (T) this;
//     }
// 
//     protected T selectPositionInRecyclerView(int position, @IdRes int recyclerView) {
//         onView(withId(recyclerView))
//                 .perform(RecyclerViewActions.actionOnItemAtPosition(position, click()));
//         return (T) this;
//     }
// 
//     public T waitFor(int seconds) throws InterruptedException {
//         Thread.sleep(seconds * 1000);
//         return (T) this;
//     }
// 
// 
//     public <K> K toRobot(Class<K> robotClass) throws IllegalAccessException, InstantiationException {
//         return robotClass.newInstance();
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/matchers/PosterMatcher.java
// public class PosterMatcher {
// 
//     public static Matcher<? super View> hasPosterAt(final int position, final String posterPath) {
//         return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
//             @Override
//             public void describeTo(Description description) {
//                 description.appendText("has poster with path:" + posterPath + " at position:" + position);
//             }
// 
//             @Override
//             protected boolean matchesSafely(RecyclerView item) {
//                 MoviePosterAdapter adapter = (MoviePosterAdapter) item.getAdapter();
//                 MoviePoster moviePoster = adapter.getItemAt(position);
//                 return moviePoster.getPosterPath().contains(posterPath);
//             }
//         };
//     }
// }


// Path: app/src/androidTest/java/com/tobi/movies/popularstream/PopularMoviesRobot.java
import android.support.test.rule.ActivityTestRule;
import com.tobi.movies.R;
import com.tobi.movies.Robot;
import com.tobi.movies.matchers.PosterMatcher;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

package com.tobi.movies.popularstream;




public class PopularMoviesRobot extends Robot<PopularMoviesRobot> {

    public static PopularMoviesRobot create() {
        return new PopularMoviesRobot();
    }

    public PopularMoviesRobot() {
    }

    public PopularMoviesRobot launchPopularMovies(ActivityTestRule<PopularMoviesActivity> rule) {
        rule.launchActivity(null);
        return this;
    }

    public PopularMoviesRobot checkPosterWithPathIsDisplayedAtPosition(int position, String posterPath) {
        onView(withId(R.id.popularMovies_recycler))
                .check(matches(PosterMatcher.hasPosterAt(position, posterPath)));