package com.example.profbola.bakingtime;

import android.support.test.espresso.ViewAssertion;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.example.profbola.bakingtime.ui.MainActivity;

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

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.not;

/**
 * Created by prof.BOLA on 7/6/2017.
 */

@RunWith(AndroidJUnit4.class)
public class RecipeActivityTest {

    public final String CAKE_NAME = "Nutella Pie";

    @Rule
    public ActivityTestRule<MainActivity> mActivityTestRule
            = new ActivityTestRule<>(MainActivity.class);


    @Test
    public void CakeName_AppearInListing() {
        onData(anything()).inAdapterView(withId(R.id.recipe_list))
                .atPosition(0).onChildView(withId(R.id.recipe_title))
                .check(matches(withText(CAKE_NAME)));
    }

    @Test
    public void clickRecipeItem_OpensDetailActivity() {
        onData(anything()).inAdapterView(withId(R.id.recipe_list))
                .atPosition(0)
                .perform(click());
        onData(anything()).inAdapterView(withId(R.id.ingredients_listing))
                .atPosition(0)
                .check((ViewAssertion) not(doesNotExist()));
    }

}

@@ -119,138 +119,466 @@
 est.
-rule.ActivityTestRule;%0Aimport android.support.test.runner.AndroidJUnit4;%0A%0Aimport com.example.profbola.bakingtime.ui.MainActivity;%0A
+espresso.contrib.RecyclerViewActions;%0Aimport android.support.test.espresso.matcher.BoundedMatcher;%0Aimport android.support.test.rule.ActivityTestRule;%0Aimport android.support.test.runner.AndroidJUnit4;%0Aimport android.support.v7.widget.RecyclerView;%0Aimport android.widget.TextView;%0A%0Aimport com.example.profbola.bakingtime.ui.MainActivity;%0Aimport com.example.profbola.bakingtime.utils.RecipeAdapter;%0A%0Aimport org.hamcrest.Description;%0Aimport org.hamcrest.Matcher;
 %0Aimp
@@ -715,16 +715,77 @@
 onData;%0A
+import static android.support.test.espresso.Espresso.onView;%0A
 import s
@@ -1582,109 +1582,415 @@
 );%0A%0A
-%0A
     
-@Test%0A    public void CakeName_AppearInListing() %7B%0A        onData(anything()).inAdapterView(with
+private Matcher%3CRecyclerView.ViewHolder%3E recipeViewHolderBoundedMatcher (final String text) %7B%0A%0A        return new BoundedMatcher%3CRecyclerView.ViewHolder, RecipeAdapter.RecipeViewHolder%3E(RecipeAdapter.RecipeViewHolder.class) %7B%0A            @Override%0A            protected boolean matchesSafely(RecipeAdapter.RecipeViewHolder item) %7B%0A                TextView titleView = (TextView) item.itemView.findViewBy
 Id(R
@@ -1997,33 +1997,33 @@
 .id.recipe_list)
-)
+;
 %0A               
@@ -2027,30 +2027,368 @@
     
-.atPosition(0).onChild
+return titleView == null ? false : titleView.getText().toString().contains(text);%0A            %7D%0A%0A            @Override%0A            public void describeTo(Description description) %7B%0A                description.appendText(%22No ViewHolder found with text: %22 + text);%0A            %7D%0A        %7D;%0A    %7D%0A%0A    @Test%0A    public void CakeName_AppearInListing() %7B%0A        on
 View
@@ -2407,21 +2407,20 @@
 .recipe_
-title
+list
 ))%0A     
@@ -2435,30 +2435,106 @@
    .
-check(matches(withText
+perform(RecyclerViewActions%0A                        .scrollToHolder(recipeViewHolderBoundedMatcher
 (CAK
@@ -2631,34 +2631,8 @@
   on
-Data(anything()).inAdapter
 View
@@ -2679,55 +2679,83 @@
    .
-atPosition(0)%0A                .perform(
+perform(RecyclerViewActions.actionOnItem(withId(R.id.recipe_list), 
 click())
 ;%0A  
@@ -2750,17 +2750,19 @@
 click())
-;
+);%0A
 %0A       
@@ -2768,34 +2768,8 @@
   on
-Data(anything()).inAdapter
 View
@@ -2824,20 +2824,74 @@
    .
-atPosition(0
+perform(RecyclerViewActions.scrollTo(withId(R.id.ingredient_name))
 )%0A  

Modify tests