@Test @MediumTest public void testSimpleMenuItemClickViaAPI() 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)); mActivityTestRule.runOnUiThread(new Runnable() { @Override public void run() { mPopupMenu.getMenu().performIdentifierAction(R.id.action_highlight, 0); } }); verify(menuBuilder.mOnMenuItemClickListener, times(1)).onMenuItemClick( mPopupMenu.getMenu().findItem(R.id.action_highlight)); 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);  }