package com.mateuszkoslacz.moviper.rxsample;


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

import com.mateuszkoslacz.moviper.rxsample.utils.RecyclerViewMatcher;
import com.mateuszkoslacz.moviper.rxsample.viper.view.activity.ListingActivity;

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

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.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

@RunWith(AndroidJUnit4.class)
public class ListingActivityTest {

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

    @Test
    public void loadUsersList() {
        onView(withRecyclerView(R.id.recycler_view).atPosition(3))
                .check(matches(hasDescendant(withText("user4"))));
    }

    public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) {
        return new RecyclerViewMatcher(recyclerViewId);
    }
}

@@ -189,31 +189,219 @@
 ple.
-utils.RecyclerViewMatch
+di.DIProvider;%0Aimport com.mateuszkoslacz.moviper.rxsample.utils.RecyclerViewMatcher;%0Aimport com.mateuszkoslacz.moviper.rxsample.utils.di.TestRepository;%0Aimport com.mateuszkoslacz.moviper.rxsample.viper.entity.Us
 er;%0A
@@ -780,16 +780,167 @@
 endant;%0A
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;%0Aimport static android.support.test.espresso.matcher.ViewMatchers.withId;%0A
 import s
@@ -1005,16 +1005,57 @@
 ithText;
+%0Aimport static org.hamcrest.Matchers.not;
 %0A%0A@RunWi
@@ -1168,16 +1168,28 @@
 ctivity%3E
+%0A           
  mActivi
@@ -1279,155 +1279,1802 @@
 oid 
-loadUsersList() %7B%0A        onView(withRecyclerView(R.id.recycler_view).atPosition(3))%0A                .check(matches(hasDescendant(withText(%22user4%22)
+testDataFetchingWithSuccess() %7B%0A        shouldLoadingViewBeDisplayed();%0A        ((TestRepository%3CUser%3E) DIProvider.getRepositoryComponent().provideUserRepository())%0A                .triggerContentReturn();%0A        shouldContentViewBeDisplayed();%0A    %7D%0A%0A    @Test%0A    public void testDataFetchingWithError() %7B%0A        shouldLoadingViewBeDisplayed();%0A        ((TestRepository%3CUser%3E) DIProvider.getRepositoryComponent().provideUserRepository())%0A                .triggerError(new IllegalStateException());%0A        shouldErrorViewBeDisplayed();%0A    %7D%0A%0A    @Test%0A    public void testDataLoadingToRecyclerView() %7B%0A        shouldLoadingViewBeDisplayed();%0A        ((TestRepository%3CUser%3E) DIProvider.getRepositoryComponent().provideUserRepository())%0A                .triggerContentReturn();%0A        shouldContentViewBeDisplayed();%0A        onView(withRecyclerView(R.id.recycler_view).atPosition(3))%0A                .check(matches(hasDescendant(withText(%22user4%22))));%0A    %7D%0A%0A    public void shouldErrorViewBeDisplayed() %7B%0A        onView(withId(R.id.loadingView)).check(matches(not(isDisplayed())));%0A        onView(withId(R.id.errorView)).check(matches(isDisplayed()));%0A        onView(withId(R.id.recycler_view)).check(matches(not(isDisplayed())));%0A    %7D%0A%0A    public void shouldLoadingViewBeDisplayed() %7B%0A        onView(withId(R.id.loadingView)).check(matches(isDisplayed()));%0A        onView(withId(R.id.errorView)).check(matches(not(isDisplayed())));%0A        onView(withId(R.id.recycler_view)).check(matches(not(isDisplayed())));%0A    %7D%0A%0A    public void shouldContentViewBeDisplayed() %7B%0A        onView(withId(R.id.loadingView)).check(matches(not(isDisplayed())));%0A        onView(withId(R.id.errorView)).check(matches(not(isDisplayed())));%0A        onView(withId(R.id.recycler_view)).check(matches(isDisplayed(
 )));

add ListingActivity tests with dummy components