TagsListActivity extends NavigationDrawerActivity implements TagsListAdapter.OnFilterChangeListener { @Override public boolean onOptionsItemSelected(MenuItem item) { DrawerLayout drawer = mFilterDrawer.mLayout; if (drawer != null) { if (item.getItemId() == R.id.action_filter_baggers) { if (drawer.isDrawerOpen(GravityCompat.END)) { drawer.closeDrawer(GravityCompat.END); } else { drawer.openDrawer(GravityCompat.END); } return true; } else if (item.getItemId() == android.R.id.home && drawer.isDrawerVisible(GravityCompat.END)) { drawer.closeDrawer(GravityCompat.END); return super.onOptionsItemSelected(item); } } return super.onOptionsItemSelected(item); }  @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onBackPressed(); @Override void onFilterChanged(List<String> selectedTagsIds); @Override void setContentView(int layoutResID);  }
@Test public void should_open_filter_drawer_when_clicking_on_menu_icon() { MenuItem item = new RoboMenuItem(R.id.action_filter_baggers); activity.onOptionsItemSelected(item); verify(drawer).openDrawer(GravityCompat.END); }
@Test public void should_close_tags_drawer_when_clicking_on_menu_icon_and_drawer_is_already_opened() { MenuItem item = new RoboMenuItem(R.id.action_filter_baggers); when(drawer.isDrawerOpen(GravityCompat.END)).thenReturn(true); activity.onOptionsItemSelected(item); verify(drawer).closeDrawer(GravityCompat.END); }