use of org.robolectric.tester.android.view.TestMenuItem in project scdl by passy.
the class PreferencesMenuTest method shouldStartPreferencesInActivity.
private void shouldStartPreferencesInActivity(Fragment fragment) {
final ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class);
controller.create().start().resume();
final FragmentActivity activity = controller.get();
activity.getSupportFragmentManager().beginTransaction().add(fragment, null).commit();
final MenuItem item = new TestMenuItem(R.id.preferences);
fragment.onOptionsItemSelected(item);
final ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
final Intent startedActivity = shadowActivity.getNextStartedActivity();
// Intent was actually started
assertThat(startedActivity, notNullValue());
final ShadowIntent intent = Robolectric.shadowOf(startedActivity);
assertThat(intent.getComponent().getClassName(), equalTo(ApplicationPreferencesActivity.class.getName()));
}
Aggregations