Merge "Fix crash when activity not attached after search index finishes." into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-12 01:31:20 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 0 deletions

View File

@@ -349,4 +349,21 @@ public class SearchFragmentTest {
verify(fragment.mSavedQueryController).loadSavedQueries();
}
@Test
public void onIndexingFinished_noActivity_shouldNotCrash() {
ActivityController<SearchActivity> activityController =
Robolectric.buildActivity(SearchActivity.class);
activityController.setup();
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
.findFragmentById(R.id.main_content));
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
.thenReturn(true);
fragment.mQuery = "bright";
ReflectionHelpers.setField(fragment, "mLoaderManager", null);
ReflectionHelpers.setField(fragment, "mHost", null);
fragment.onIndexingFinished();
// no crash
}
}