Search in sources :

Example 6 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class FavoriteActivityTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    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_vote));
    verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture());
    userServicesCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) IOException(java.io.IOException) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 7 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class FavoriteActivityTest method testVoteItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItem() {
    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_vote));
    verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture());
    userServicesCallback.getValue().onDone(true);
    assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 8 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class FavoriteActivityTest method testShare.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testShare() {
    TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
    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_share));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_SEND);
}
Also used : Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 9 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method testVoteItemPromptToLogin.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemPromptToLogin() {
    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(false);
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, LoginActivity.class);
}
Also used : Context(android.content.Context) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 10 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testReply.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    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");
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

RoboMenuItem (org.robolectric.fakes.RoboMenuItem)108 Test (org.junit.Test)101 MenuItem (android.view.MenuItem)72 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 TargetApi (android.annotation.TargetApi)18 PopupMenu (android.widget.PopupMenu)18 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)18 Context (android.content.Context)11 Intent (android.content.Intent)8 Before (org.junit.Before)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)6 SuppressLint (android.annotation.SuppressLint)4 WebView (android.webkit.WebView)3 TestItem (io.github.hidroh.materialistic.test.TestItem)3 ShadowWebView (io.github.hidroh.materialistic.test.shadow.ShadowWebView)3 IOException (java.io.IOException)3 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 Fragment (android.support.v4.app.Fragment)2 RecyclerView (android.support.v7.widget.RecyclerView)2