public static void assertButtonClickLaunchesActivity(Activity activity, Button btn, String targetActivityName) { btn.performClick(); ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ShadowIntent shadowIntent = shadowOf(startedIntent); assertThat(shadowIntent.getComponent().getClassName(), equalTo(targetActivityName)); }
MenuItem item = new TestMenuItem() { public int getItemId() { return R.id.hello; } }; activity.onOptionsItemSelected(item); ShadowActivity shadowActivity = Robolectric.shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent); assertThat(shadowIntent.getComponent().getClassName(), equalTo(HelloActivity_.class.getName()));
// Get shadow ShadowActivity shadowActivity = Shadows.shadowOf(activity); // Click menu shadowActivity.clickMenuItem(R.id.settings_option_item); // Get intent Intent startedIntent = shadowActivity.getNextStartedActivity(); ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent); // Make your assertion assertThat(shadowIntent.getComponent().getClassName(), equalTo(HelloActivity_.class.getName()));
ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ShadowIntent shadowIntent = shadowOf(startedIntent); assertThat(shadowIntent.getComponent().getClassName(), equalTo(targetActivityName));
@Test public void shouldDisplayDetailActivityWhenAdapterClicked() throws Exception{ List<ImageNode> nodes = new ArrayList<ImageNode>(); ImageNode node = new ImageNode(); node.setId(36597698); node.setContributorId("halfpoint"); node.setFileName("halfpoint150200457"); node.setFolder("halfpoint1502"); node.setDescription("halfpoint1502"); node.setMediaType("halfpoint1502"); node.setUrlThumb(URLHelper.buildThumbUrl( node.getId(), node.getContributorId(), node.getFolder(), node.getFileName(), node.getDescription())); node.setUrlFullSize(URLHelper.buildFullSizeUrl(node.getUrlThumb())); nodes.add(node); DetailLikeBoxAdapter mAdapter = new DetailLikeBoxAdapter(activity, nodes); GridView gridView = (GridView) activity.findViewById(R.id.likebox_gridview); gridView.setAdapter(mAdapter); View itemView = mAdapter.getView(0, null, gridView); gridView.performItemClick(itemView, 0, mAdapter.getItemId(0)); Intent startedIntent = shadowOf(activity).getNextStartedActivity(); ShadowIntent shadowIntent = shadowOf(startedIntent); // create shadow intent which starts next activity System.out.println(DetailActivity.class.getName()+" "+shadowIntent.getComponent().getClassName() ); assertEquals(DetailActivity.class.getName(), shadowIntent.getComponent().getClassName()); // compare shadow intent w/ desired next activity }
if (getComponent() != other.getComponent()) { if (getComponent() != null) { if (!getComponent().equals(other.getComponent())) { return false; if (!other.getComponent().equals(getComponent())) { return false;