use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ItemActivityTest method testOptionExternal.
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
controller.withIntent(intent).create().start().resume();
// inflate menu, see https://github.com/robolectric/robolectric/issues/1326
ShadowLooper.pauseMainLooper();
controller.visible();
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
// open article
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
// open item
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testReply.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
viewHolder.itemView.findViewById(R.id.button_more).performClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment));
assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class).hasExtra(ComposeActivity.EXTRA_PARENT_ID, "1");
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testVote.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVote() {
viewHolder.itemView.findViewById(R.id.button_more).performClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
verify(userServices).voteUp(any(Context.class), any(), voteCallback.capture());
voteCallback.getValue().onDone(true);
assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast());
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class FavoriteActivityTest method testDelete.
@Test
public void testDelete() {
RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
holder.itemView.performLongClick();
ActionMode actionMode = mock(ActionMode.class);
activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
assertEquals(2, adapter.getItemCount());
activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
dialog = ShadowAlertDialog.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
verify(favoriteManager).remove(any(Context.class), selection.capture());
assertThat(selection.getValue()).contains("1");
verify(actionMode).finish();
when(favoriteManager.getSize()).thenReturn(1);
observerCaptor.getValue().onChanged();
assertEquals(1, adapter.getItemCount());
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class FavoriteActivityTest method testReply.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
Assert.assertNotNull(popupMenu);
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment));
assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class);
}
Aggregations