DrawerPresenter extends BaseActivityPresenter<DrawerActivityView> { @Override public boolean onBackPressed() { if (view.isNavigationDrawerOpen()) { view.closeNavigationDrawer(); return true; } else if (toolbarTitle != R.string.drawer_nav_schedule) { int firstItem = R.id.drawer_nav_schedule; onNavigationItemSelected(firstItem); view.selectDrawerMenuItem(firstItem); return true; } return false; } DrawerPresenter(DrawerActivityView view); @Override void onPostCreate(Bundle savedInstanceState); @Override void onRestoreInstanceState(Bundle savedInstanceState); @Override void onNavigationItemSelected(@IdRes int itemId); @Override boolean onBackPressed();  }
@Test public void should_close_navigation_drawer_when_pressing_back_if_already_opened() { when(view.isNavigationDrawerOpen()).thenReturn(true); boolean result = presenter.onBackPressed(); assertThat(result).isTrue(); verify(view).closeNavigationDrawer(); }
@Test public void should_go_back_to_agenda_when_pressing_back_while_navigation_drawer_is_already_closed_and_category_is_not_schedule() { presenter.toolbarTitle = R.string.drawer_nav_speakers; when(view.isNavigationDrawerOpen()).thenReturn(false); boolean result = presenter.onBackPressed(); assertThat(result).isTrue(); verify(view).selectDrawerMenuItem(R.id.drawer_nav_schedule); verify(view, times(1)).closeNavigationDrawer(); }
@Test public void should_go_back_when_pressing_back_while_navigation_drawer_is_already_closed_and_category_is_schedule() { presenter.toolbarTitle = R.string.drawer_nav_schedule; when(view.isNavigationDrawerOpen()).thenReturn(false); boolean result = presenter.onBackPressed(); assertThat(result).isFalse(); verify(view, never()).selectDrawerMenuItem(R.id.drawer_nav_schedule); verify(view, never()).closeNavigationDrawer(); }