@Test public void multipleIdsSelected() { MenuItem item = mock(MenuItem.class); when(item.getItemId()).thenReturn(R.id.menu_search); boolean result = activity.onOptionsItemSelected(item); assertThat(activity.multipleMenuItems).isTrue(); assertThat(result).isFalse(); activity.multipleMenuItems = false; when(item.getItemId()).thenReturn(R.id.menu_share); result = activity.onOptionsItemSelected(item); assertThat(activity.multipleMenuItems).isTrue(); assertThat(result).isFalse(); }
@Test public void defaultIdUnderscore() { MenuItem item = mock(MenuItem.class); when(item.getItemId()).thenReturn(R.id.menu_add); activity.onOptionsItemSelected(item); assertThat(activity.menuAdd).isTrue(); }
@Test public void defaultIdSelected() { MenuItem item = mock(MenuItem.class); when(item.getItemId()).thenReturn(R.id.menu_refresh); activity.onOptionsItemSelected(item); assertThat(activity.menuRefreshSelected).isTrue(); }
@Test public void subclassTakesPrecedenceInMenuItemHandling() { MenuItem item = mock(MenuItem.class); when(item.getItemId()).thenReturn(R.id.menu_refresh); activity.onOptionsItemSelected(item); assertThat(activity.menuRefreshSelected).isTrue(); assertThat(activity.menuRefreshSelectedFromAnnotatedClass).isFalse(); }