@Test
 public void testGoingNoWhereGetsYouNoWhere() throws Exception {
   multiActivityManager.setTabbedPanel(tabbedPanel);
   PlaceChangeEvent placeChangeEvent = setUpPlaceChangeEvent(Place.NOWHERE);
   multiActivityManager.onPlaceChange(placeChangeEvent);
   verify(tabbedPanel, never()).show(any(Place.class));
   verify(tabbedPanel, never()).addTab(anyString(), Matchers.<IsWidget>any(), any(Place.class));
 }
  @Test
  public void testClosingATabIsBlockedByTheActivity() throws Exception {
    Place place = mock(Place.class);
    multiActivityManager.setTabbedPanel(tabbedPanel);

    Activity activity = goTo(place);
    when(activity.mayStop()).thenReturn(false);

    multiActivityManager.onCloseTab(new ClosePlaceEvent(place));
    verify(activity, never()).onStop();
  }
  private Activity goTo(Place place) {
    Activity activity = setUpActivityForAPlace(place);
    PlaceChangeEvent placeChangeEvent = setUpPlaceChangeEvent(place);

    multiActivityManager.onPlaceChange(placeChangeEvent);

    return activity;
  }
  @Test
  public void testChangePlace() throws Exception {
    Place oldPlace = mock(Place.class);
    Place newPlace = mock(Place.class);

    multiActivityManager.setTabbedPanel(tabbedPanel);

    verifyGoToNewPlace(oldPlace, "oldMockTabTitle");
    verifyGoToNewPlace(newPlace, "newMockTabTitle");
  }
  @Test
  public void testPlaceGetsShownIfItAlreadyActive() throws Exception {
    Place oldPlace = mock(Place.class);
    Place newPlace = mock(Place.class);

    multiActivityManager.setTabbedPanel(tabbedPanel);

    verifyGoToNewPlace(oldPlace, "oldMockTabTitle");
    verifyGoToExistingPlace(newPlace);
  }
  @Test
  public void testCloseTabCallsOnStopAndRemovesWrappersHandlers() throws Exception {
    Place place = mock(Place.class);
    multiActivityManager.setTabbedPanel(tabbedPanel);
    ArgumentCaptor<ResettableEventBus> resettableEventBusArgumentCaptor =
        ArgumentCaptor.forClass(ResettableEventBus.class);

    HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    ClosePlaceEvent.Handler handler = mock(ClosePlaceEvent.Handler.class);
    when(eventBus.addHandler(ClosePlaceEvent.TYPE, handler)).thenReturn(handlerRegistration);

    Activity activity = goTo(place);

    when(activity.mayStop()).thenReturn(true);

    verify(activity).start(any(AcceptTabItem.class), resettableEventBusArgumentCaptor.capture());
    resettableEventBusArgumentCaptor.getValue().addHandler(ClosePlaceEvent.TYPE, handler);

    multiActivityManager.onCloseTab(new ClosePlaceEvent(place));
    verify(activity).onStop();
    verify(handlerRegistration).removeHandler();
  }
 @Test
 public void testItIsSafeToCloseATabThatDoesNotExist() throws Exception {
   multiActivityManager.onCloseTab(new ClosePlaceEvent(new AssetEditorPlace("I-do-Not-Exist")));
   // Does nothing
 }
 @Test(expected = IllegalStateException.class)
 public void testTabbedPanelIsNotSet() throws Exception {
   PlaceChangeEvent placeChangeEvent = mock(PlaceChangeEvent.class);
   multiActivityManager.onPlaceChange(placeChangeEvent);
 }
 @Test(expected = IllegalStateException.class)
 public void testTabbedPanelCanOnlyBeSetOnce() throws Exception {
   multiActivityManager.setTabbedPanel(tabbedPanel);
   multiActivityManager.setTabbedPanel(tabbedPanel);
 }