MultiChoiceToolbarHelper { void updateToolbar(int itemNumber) throws IllegalStateException { if (itemNumber == ZERO) { showDefaultToolbar(); } else if (itemNumber > ZERO) { showMultiChoiceToolbar(); } updateToolbarTitle(itemNumber); } MultiChoiceToolbarHelper(MultiChoiceToolbar multiChoiceToolbar);   }
@Test public void testGivenZeroItemSelectedWhenUpdateToolbarThenDefaultIconShown() throws Exception { int itemSelected = 0; int icon = 1; when(mMockMultiChoiceToolbar.getIcon()).thenReturn(icon); mCut.updateToolbar(itemSelected); verify(mMockMultiChoiceToolbar, times(1)).getIcon(); verify(mMockActionBar, times(1)).setHomeAsUpIndicator(icon); verify(mMockActionBar, times(1)).setDisplayHomeAsUpEnabled(true); verify(mMockToolbar, times(1)).setNavigationOnClickListener(mMockMultiChoiceToolbar.getIconAction()); }
@Test public void testGivenZeroItemSelectedAndNoIconWhenUpdateToolbarThenNoIconShown() throws Exception { int itemSelected = 0; mCut.updateToolbar(itemSelected); verify(mMockMultiChoiceToolbar, times(1)).getIcon(); verify(mMockActionBar, times(1)).setDisplayHomeAsUpEnabled(false); verify(mMockActionBar, times(0)).setHomeAsUpIndicator(any(Integer.class)); verify(mMockToolbar, times(0)).setNavigationOnClickListener(any(View.OnClickListener.class)); }
@Test public void testGivenZeroItemSelectedWhenUpdateToolbarThenDefaultBackgroundSet() throws Exception { int itemSelected = 0; mCut.updateToolbar(itemSelected); verify(mMockActionBar, times(1)).setBackgroundDrawable(any(ColorDrawable.class)); verify(mMockMultiChoiceToolbar, times(1)).getDefaultPrimaryColor(); }
@Test public void testGivenOneItemSelectedWhenUpdateToolbarThenXIconSet() throws Exception { int itemSelected = 1; mCut.updateToolbar(itemSelected); verify(mMockActionBar, times(1)).setHomeAsUpIndicator(R.drawable.ic_close_white_24dp); verify(mMockActionBar, times(1)).setDisplayHomeAsUpEnabled(true); }
@Test public void testGivenOneItemSelectedWhenUpdateToolbarThenOnClickListenerSet() throws Exception { int itemSelected = 1; mCut.updateToolbar(itemSelected); verify(mMockToolbar, times(1)).setNavigationOnClickListener(any(View.OnClickListener.class)); }
@Test public void testGivenOneItemSelectedWhenUpdateToolbarAndClickOnIconPerformedThenListenerInterfaceClick() throws Exception { int itemSelected = 1; mCut.updateToolbar(itemSelected); verify(mMockToolbar, times(1)).setNavigationOnClickListener(any(View.OnClickListener.class)); }