use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testVoteItemFailed.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
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().onError(new IOException());
assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ListFragmentTest method testListMenu.
@Test
public void testListMenu() {
Bundle args = new Bundle();
args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName());
args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE);
activity.getSupportFragmentManager().beginTransaction().add(android.R.id.list, Fragment.instantiate(activity, ListFragment.class.getName(), args), ListFragment.class.getName()).commit();
activity.getSupportFragmentManager().findFragmentByTag(ListFragment.class.getName()).onOptionsItemSelected(new RoboMenuItem(R.id.menu_list));
assertThat(activity.getSupportFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ReadabilityFragmentTest method testWebToggle.
@Test
public void testWebToggle() {
fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_readability));
WebView webView = (WebView) activity.findViewById(R.id.web_view);
shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowOf(webView).getLastLoadedUrl()).isEqualTo("http://example.com/article.html");
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ReadabilityFragmentTest method testFullscreenMenu.
@SuppressLint("NewApi")
@Test
public void testFullscreenMenu() {
verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture());
callback.getValue().onResponse("<div>content</div>");
ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
activity.findViewById(R.id.button_more).performClick();
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_font_options));
assertThat(fragment.getFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.
the class ItemActivityTest method testShare.
@SuppressLint("NewApi")
@Test
public void testShare() {
TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
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();
// share article
shadowOf(activity).clickMenuItem(R.id.menu_share);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
Intent actual = shadowOf(activity).getNextStartedActivity();
assertThat(actual).hasAction(Intent.ACTION_SEND);
// share item
shadowOf(activity).clickMenuItem(R.id.menu_share);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
actual = shadowOf(activity).getNextStartedActivity();
assertThat(actual).hasAction(Intent.ACTION_SEND);
}
Aggregations