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);
}
}
}
Aggregations