I'm trying to grab a reference of an Activity's MenuItem to Assert that it's displaying the correct drawable as its icon.
I've tried reference the MenuItem by its ID (as several people have mentioned after some searching) by doing
@Test
public void testMenuItemIcon() {
...
MenuItem menuItem = activity.findViewById(R.id.menu_item_id);
activity.methodThatModifiesMenuItemIcon();
...
// Assert that menuItem icon has been modified correctly
}
but when I run it I get
java.lang.ClassCastException: android.support.v7.view.menu.ActionMenuItemView cannot be cast to android.view.MenuItem
Goal: I want to be able to reference an activity's MenuItem, perform some action, and assert that the MenuItem's icon was updated to the correct drawable.