package com.movies.tobi.popularmovies.steps;

import android.support.test.espresso.contrib.RecyclerViewActions;

import com.movies.tobi.popularmovies.R;

import cucumber.api.DataTable;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.*;

public class PopularMoviesSteps {

    @When("^I select the poster at position (\\d+)$")
    public static void I_select_a_poster(final int position) {
        onView(withId(R.id.popularMovies_recycler))
                .perform(RecyclerViewActions.actionOnItemAtPosition(position, click()));

    }

    @Then("^I expect to see the following movie details$")
    public static void I_expect_to_see_the_movie_details(final DataTable dataTable) {
        onView(withText("Deadpool")).check(matches(isDisplayed()));
    }
}

@@ -147,16 +147,39 @@
 ies.R;%0A%0A
+import java.util.Map;%0A%0A
 import c
@@ -201,16 +201,16 @@
 aTable;%0A
-
 import c
@@ -546,16 +546,61 @@
 chers.*;
+%0Aimport static org.hamcrest.core.AllOf.allOf;
 %0A%0Apublic
@@ -689,31 +689,24 @@
 %0A    public 
-static 
 void I_selec
@@ -957,23 +957,16 @@
  public 
-static 
 void I_e
@@ -1037,34 +1037,544 @@
     
-onView(withText(%22Deadpool%22
+if (dataTable.asMaps(String.class, String.class).size() %3E 1) %7B%0A            throw new IllegalArgumentException(%22We can just display one movie per time%22);%0A        %7D%0A%0A        final Map%3CString, String%3E row = dataTable.asMaps(String.class, String.class).get(0);%0A%0A        String movieTitle = row.get(%22movieTitle%22);%0A        String movieDetails = row.get(%22movieDetails%22);%0A%0A        onView(allOf(withId(R.id.movieTitle), withText(movieTitle))).check(matches(isDisplayed()));%0A        onView(allOf(withId(R.id.movieOverview), withText(movieDetails)
 )).c

assert movie title and details