@Test @MediumTest public void testSubMenuClicksViaEvent() throws Throwable { Builder menuBuilder = new Builder().withMenuItemClickListener(); menuBuilder.wireToActionButton(); onView(withId(R.id.test_button)).perform(click()); verify(menuBuilder.mOnMenuItemClickListener, never()).onMenuItemClick(any(MenuItem.class)); onView(withText(mResources.getString(R.string.popup_menu_share))) .inRoot(withDecorView(not(is(mMainDecorView)))) .perform(click()); verify(menuBuilder.mOnMenuItemClickListener, times(1)).onMenuItemClick( mPopupMenu.getMenu().findItem(R.id.action_share)); Thread.sleep(1000); onView(withClassName(Matchers.is(DROP_DOWN_CLASS_NAME))) .inRoot(allOf(withDecorView(not(is(mMainDecorView))), hasWindowFocus())) .check(matches(isDisplayed())); onView(withText(mResources.getString(R.string.popup_menu_share_email))) .inRoot(allOf(withDecorView(not(is(mMainDecorView))), hasWindowFocus())) .check(matches(isDisplayed())); onView(withText(mResources.getString(R.string.popup_menu_share_circles))) .inRoot(allOf(withDecorView(not(is(mMainDecorView))), hasWindowFocus())) .check(matches(isDisplayed())); onView(withText(mResources.getString(R.string.popup_menu_share_circles))) .inRoot(allOf(withDecorView(not(is(mMainDecorView))), hasWindowFocus())) .perform(click()); verify(menuBuilder.mOnMenuItemClickListener, times(1)).onMenuItemClick( mPopupMenu.getMenu().findItem(R.id.action_share_circles)); onView(withClassName(Matchers.is(DROP_DOWN_CLASS_NAME))).check(doesNotExist()); }
@NonNull public Menu getMenu() { return mMenu; }
PopupMenu { @NonNull public Menu getMenu() { return mMenu; } }
PopupMenu { @NonNull public Menu getMenu() { return mMenu; } PopupMenu(@NonNull Context context, @NonNull View anchor);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity,
            @AttrRes int popupStyleAttr, @StyleRes int popupStyleRes); }
PopupMenu { @NonNull public Menu getMenu() { return mMenu; } PopupMenu(@NonNull Context context, @NonNull View anchor);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity,
            @AttrRes int popupStyleAttr, @StyleRes int popupStyleRes); void setGravity(int gravity); int getGravity(); @NonNull View.OnTouchListener getDragToOpenListener(); @NonNull Menu getMenu(); @NonNull MenuInflater getMenuInflater(); void inflate(@MenuRes int menuRes); void show(); void dismiss(); void setOnMenuItemClickListener(@Nullable OnMenuItemClickListener listener); void setOnDismissListener(@Nullable OnDismissListener listener); }
PopupMenu { @NonNull public Menu getMenu() { return mMenu; } PopupMenu(@NonNull Context context, @NonNull View anchor);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity);  PopupMenu(@NonNull Context context, @NonNull View anchor, int gravity,
            @AttrRes int popupStyleAttr, @StyleRes int popupStyleRes); void setGravity(int gravity); int getGravity(); @NonNull View.OnTouchListener getDragToOpenListener(); @NonNull Menu getMenu(); @NonNull MenuInflater getMenuInflater(); void inflate(@MenuRes int menuRes); void show(); void dismiss(); void setOnMenuItemClickListener(@Nullable OnMenuItemClickListener listener); void setOnDismissListener(@Nullable OnDismissListener listener);  }