MenuSwitcher { public WorldEditorMenu addEditorMenu() { if (editorMenuIsPresent()) { return Classes.from(fragmentManager.findFragmentByTag(WorldEditorMenuFragment.TAG)); } else { WorldEditorMenu worldEditorMenu = new WorldEditorMenuFragment(); fragmentManager.beginTransaction().replace(R.id.menu_container, worldEditorMenu.getFragment(), WorldEditorMenuFragment.TAG).commit(); return worldEditorMenu; } } @VisibleForTesting protected  MenuSwitcher(FragmentManager fragmentManager); static MenuSwitcher newInstance(); MainMenu addMainMenu(); WorldEditorMenu addEditorMenu(); ImageLoader addImageLoader();  }
@Test public void testThatWhenEditorMenuIsNotPresentThenAddEditorMenuBeginsTransaction() { givenThatEditorMenuIsNotPresent(); menuSwitcher.addEditorMenu(); verify(fragmentManager).beginTransaction(); }
@Test public void testThatWhenEditorMenuIsNotPresentThenAddEditorMenuPerformsReplaceAndCommit() { givenThatEditorMenuIsNotPresent(); menuSwitcher.addEditorMenu(); InOrder inOrder = inOrder(fragmentTransaction, fragmentTransaction); inOrder.verify(fragmentTransaction).replace(eq(R.id.menu_container), any(WorldEditorMenuFragment.class), eq(WorldEditorMenuFragment.TAG)); inOrder.verify(fragmentTransaction).commit(); }
@Test public void testThatWhenEditorMenuIsPresentThenAddEditorMenuFindsFragmentByTag() { givenThatEditorMenuIsPresent(); menuSwitcher.addEditorMenu(); verify(fragmentManager, times(2)).findFragmentByTag(WorldEditorMenuFragment.TAG); }