Search in sources :

Example 1 with ThrottleContentObserverIdlingResource

use of com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource in project iosched by google.

the class MyScheduleActivityTest method newDataObtained_DataUpdated.

@Test
public void newDataObtained_DataUpdated() {
    IdlingResource idlingResource = null;
    try {
        // Given initial data displayed
        showDay(2);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_BEFORE)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_2)).check(doesNotExist());
        showDay(1);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_AFTER)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_1)).check(doesNotExist());
        // When new data is available
        mStubMyScheduleModel.setMockScheduleDataDay1(MyScheduleMockItems.getItemsForAttendee(1, false, MyScheduleMockItems.SESSION_TITLE_1));
        mStubMyScheduleModel.setMockScheduleDataDay2(MyScheduleMockItems.getItemsForAttendee(2, false, MyScheduleMockItems.SESSION_TITLE_2));
        mStubMyScheduleModel.fireContentObserver();
        // Wait for the ThrottleContentObserver to process the event
        idlingResource = new ThrottleContentObserverIdlingResource(InstrumentationRegistry.getTargetContext());
        Espresso.registerIdlingResources(idlingResource);
        // Then the new data is shown
        onView(withText(MyScheduleMockItems.SESSION_TITLE_1)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_AFTER)).check(doesNotExist());
        showDay(2);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_2)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_BEFORE)).check(doesNotExist());
    } finally {
        if (idlingResource != null) {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
Also used : ThrottleContentObserverIdlingResource(com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource) ThrottleContentObserverIdlingResource(com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource) IdlingResource(android.support.test.espresso.IdlingResource) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Aggregations

IdlingResource (android.support.test.espresso.IdlingResource)1 FlakyTest (android.support.test.filters.FlakyTest)1 LargeTest (android.support.test.filters.LargeTest)1 ThrottleContentObserverIdlingResource (com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource)1 Test (org.junit.Test)1