Search in sources :

Example 66 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    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_vote));
    verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
    voteCallback.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 67 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testViewUser.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testViewUser() {
    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_profile));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, UserActivity.class).hasExtra(UserActivity.EXTRA_USERNAME, "author");
}
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)

Example 68 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testVoteItemPromptToLogin.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemPromptToLogin() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).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), eq(item.getId()), 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 69 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testShare.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testShare() {
    TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
    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_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 70 with RoboMenuItem

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

the class ItemFragmentMultiPageTest method testDisplayMenu.

@Test
public void testDisplayMenu() {
    WebItem webItem = mock(WebItem.class);
    when(webItem.getId()).thenReturn("1");
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
    makeVisible(fragment);
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_comments));
    assertThat(fragment.getFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
Also used : Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) Fragment(android.support.v4.app.Fragment) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

RoboMenuItem (org.robolectric.fakes.RoboMenuItem)127 Test (org.junit.Test)120 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 RoboMenu (org.robolectric.fakes.RoboMenu)12 Context (android.content.Context)11 Intent (android.content.Intent)9 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 ShadowActivity (org.robolectric.shadows.ShadowActivity)3 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2