/** * Closes the splash screen associated with the given place request, if any. Internally, this method should be * invoked every time a part or perspective is removed from the workbench (cleaning up after the corresponding * earlier call to {@link #addSplashScreenFor(PlaceRequest)}. * @param place the place whose opening may have triggered a splash screen to launch. Must not be null. */ private void closeSplashScreen(final PlaceRequest place) { SplashScreenActivity splashScreenActivity = availableSplashScreens.remove(place.getIdentifier()); if (splashScreenActivity != null) { try { splashScreenActivity.closeIfOpen(); } catch (Exception ex) { lifecycleErrorHandler.handle(splashScreenActivity, LifecyclePhase.CLOSE, ex); } activityManager.destroyActivity(splashScreenActivity); newSplashScreenActiveEvent.fire(new NewSplashScreenActiveEvent()); } }
private SplashScreenActivity makeSplashScreenThatIntercepts(final PlaceRequest place, final boolean enabled) { String splashActivityName = place.getIdentifier() + "!Splash"; SplashScreenActivity splashScreenActivity = mock(SplashScreenActivity.class); when(splashScreenActivity.isEnabled()).thenReturn(enabled); when(splashScreenActivity.intercept(place)).thenReturn(true); when(splashScreenActivity.getPlace()).thenReturn(new DefaultPlaceRequest(splashActivityName)); makeSingletonBean(SplashScreenActivity.class, splashScreenActivity); return splashScreenActivity; }
@Override public void execute() { activity.forceShow(); } }));
@Override public SplashScreenActivity getSplashScreenInterceptor(final PlaceRequest placeRequest) { SplashScreenActivity resultBean = null; for (SplashScreenActivity splashScreen : activityBeansCache.getSplashScreens()) { if (splashScreen.intercept(placeRequest)) { if (splashScreen.isEnabled()) { resultBean = splashScreen; break; } } } return startIfNecessary(secure(resultBean), placeRequest); }
@Test public void testPartLaunchWithSplashScreen() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); assertTrue(placeManager.getActiveSplashScreens().contains(lollipopGuildActivity)); verify(lollipopGuildActivity, never()).onStartup(any(PlaceRequest.class)); InOrder inOrder = inOrder(lollipopGuildActivity, newSplashScreenActiveEvent); inOrder.verify(lollipopGuildActivity).onOpen(); inOrder.verify(newSplashScreenActiveEvent).fire(any(NewSplashScreenActiveEvent.class)); }
@Test public void testProperSplashScreenShutdownOnPartClose() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); placeManager.closePlace(oz); assertTrue(placeManager.getActiveSplashScreens().isEmpty()); verify(lollipopGuildActivity).closeIfOpen(); // splash screens are Application Scoped, but we still "destroy" them (activity manager will call their onShutdown) verify(activityManager).destroyActivity(lollipopGuildActivity); }
/** * Ensures that splash screens can't be launched on their own (they should only launch as a side effect of launching * a place that they intercept). This test came from the original test suite, and may not be all that relevant * anymore: it assumes that the ActivityManager might resolve a PlaceRequest to a SplashScreenActivity, and this is * currently not in the ActivityManager contract. */ @Test public void testSplashScreenActivityShouldNotLaunchOnItsOwn() throws Exception { final PlaceRequest somewhere = new DefaultPlaceRequest("Somewhere"); final SplashScreenActivity splashScreenActivity = mock(SplashScreenActivity.class); when(activityManager.getActivities(somewhere)).thenReturn(singleton((Activity) splashScreenActivity)); placeManager.goTo(somewhere); verify(splashScreenActivity, never()).onStartup(eq(somewhere)); verify(splashScreenActivity, never()).onOpen(); verify(newSplashScreenActiveEvent, never()).fire(any(NewSplashScreenActiveEvent.class)); assertFalse(placeManager.getActiveSplashScreens().contains(splashScreenActivity)); }
@Test public void shouldNotGetConfusedAboutSplashScreensWithSamePlaceAsTheirScreen() throws Exception { List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); when(expectedSplashScreenActivity.getPlace()).thenReturn(kansas); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); // this loads the regular kansas activity (not the splash screen) into the activityBeansCache activityManager.getActivity(kansas); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); // this must not get confused even though expectedSplashScreenActivity and kansasActivity both have the same PlaceRequest activityManager.destroyActivity(splashScreenActivity); verify(expectedSplashScreenActivity, times(1)).onShutdown(); assertFalse(activityManager.isStarted(expectedSplashScreenActivity)); // never try to destroy singleton beans! verify(iocManager, never()).destroyBean(expectedSplashScreenActivity); }
/** * Finds and opens the splash screen for the given place, if such a splash screen exists. The splash screen might * not actually display; each splash screen keeps track of its own preference setting for whether or not the user * wants to see it. * <p/> * Whether or not it chooses to display itself, the splash screen will be recorded in * {@link #availableSplashScreens} for lookup (for example, see {@link SplashScreenMenuPresenter}) and later disposal. * Internally, this method should be called every time any part or perspective is added to the workbench, and called * again when that part or perspective is removed. * @param place the place that has just been added to the workbench. Must not be null. */ private void addSplashScreenFor(final PlaceRequest place) { final SplashScreenActivity splashScreen = activityManager.getSplashScreenInterceptor(place); if (splashScreen != null) { availableSplashScreens.put(place.getIdentifier(), splashScreen); try { splashScreen.onOpen(); } catch (Exception ex) { availableSplashScreens.remove(place.getIdentifier()); lifecycleErrorHandler.handle(splashScreen, LifecyclePhase.OPEN, ex); activityManager.destroyActivity(splashScreen); return; } } newSplashScreenActiveEvent.fire(new NewSplashScreenActiveEvent()); }
/** * At the time this test was made, splash screens were handled as special cases because they're ApplicationScoped rather than Dependent. */ @Test public void shouldStopSplashScreensWhenDestroyed() throws Exception { List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); activityManager.destroyActivity(splashScreenActivity); verify(expectedSplashScreenActivity, times(1)).onShutdown(); assertFalse(activityManager.isStarted(expectedSplashScreenActivity)); // never try to destroy singleton beans! verify(iocManager, never()).destroyBean(expectedSplashScreenActivity); }
/** * At the time this test was made, splash screens were handled as special cases because they're ApplicationScoped rather than Dependent. */ @Test public void shouldStartSplashScreens() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); SplashScreenActivity nonExpectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(oz); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); assertSame(expectedSplashScreenActivity, splashScreenActivity); verify(splashScreenActivity, times(1)).onStartup(kansas); verify(nonExpectedSplashScreenActivity, never()).onStartup(any(PlaceRequest.class)); }
@SuppressWarnings("unused") private void onNewSplashScreen(@Observes NewSplashScreenActiveEvent event) { List<SplashScreenListEntry> splashScreens = new ArrayList<SplashScreenListEntry>(); for (final SplashScreenActivity activity : placeManager.getActiveSplashScreens()) { splashScreens.add(new SplashScreenListEntry(activity.getTitle(), new Command() { @Override public void execute() { activity.forceShow(); } })); } view.setSplashScreenList(splashScreens); }
@Test public void testPartLaunchWithSplashScreen() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); assertTrue(placeManager.getActiveSplashScreens().contains(lollipopGuildActivity)); verify(lollipopGuildActivity, never()).onStartup(any(PlaceRequest.class)); InOrder inOrder = inOrder(lollipopGuildActivity, newSplashScreenActiveEvent); inOrder.verify(lollipopGuildActivity).onOpen(); inOrder.verify(newSplashScreenActiveEvent).fire(any(NewSplashScreenActiveEvent.class)); }
@Test public void testProperSplashScreenShutdownOnPartClose() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); placeManager.closePlace(oz); assertTrue(placeManager.getActiveSplashScreens().isEmpty()); verify(lollipopGuildActivity).closeIfOpen(); // splash screens are Application Scoped, but we still "destroy" them (activity manager will call their onShutdown) verify(activityManager).destroyActivity(lollipopGuildActivity); }
/** * Ensures that splash screens can't be launched on their own (they should only launch as a side effect of launching * a place that they intercept). This test came from the original test suite, and may not be all that relevant * anymore: it assumes that the ActivityManager might resolve a PlaceRequest to a SplashScreenActivity, and this is * currently not in the ActivityManager contract. */ @Test public void testSplashScreenActivityShouldNotLaunchOnItsOwn() throws Exception { final PlaceRequest somewhere = new DefaultPlaceRequest("Somewhere"); final SplashScreenActivity splashScreenActivity = mock(SplashScreenActivity.class); when(activityManager.getActivities(somewhere)).thenReturn(singleton((Activity) splashScreenActivity)); placeManager.goTo(somewhere); verify(splashScreenActivity, never()).onStartup(eq(somewhere)); verify(splashScreenActivity, never()).onOpen(); verify(newSplashScreenActiveEvent, never()).fire(any(NewSplashScreenActiveEvent.class)); assertFalse(placeManager.getActiveSplashScreens().contains(splashScreenActivity)); }
@Test public void shouldNotGetConfusedAboutSplashScreensWithSamePlaceAsTheirScreen() throws Exception { List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); when(expectedSplashScreenActivity.getPlace()).thenReturn(kansas); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); // this loads the regular kansas activity (not the splash screen) into the activityBeansCache activityManager.getActivity(kansas); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); // this must not get confused even though expectedSplashScreenActivity and kansasActivity both have the same PlaceRequest activityManager.destroyActivity(splashScreenActivity); verify(expectedSplashScreenActivity, times(1)).onShutdown(); assertFalse(activityManager.isStarted(expectedSplashScreenActivity)); // never try to destroy singleton beans! verify(iocManager, never()).destroyBean(expectedSplashScreenActivity); }
/** * At the time this test was made, splash screens were handled as special cases because they're ApplicationScoped rather than Dependent. */ @Test public void shouldStopSplashScreensWhenDestroyed() throws Exception { List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); activityManager.destroyActivity(splashScreenActivity); verify(expectedSplashScreenActivity, times(1)).onShutdown(); assertFalse(activityManager.isStarted(expectedSplashScreenActivity)); // never try to destroy singleton beans! verify(iocManager, never()).destroyBean(expectedSplashScreenActivity); }
/** * At the time this test was made, splash screens were handled as special cases because they're ApplicationScoped rather than Dependent. */ @Test public void shouldStartSplashScreens() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); List<SplashScreenActivity> splashScreenList = new ArrayList<SplashScreenActivity>(); SplashScreenActivity expectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(kansas); SplashScreenActivity nonExpectedSplashScreenActivity = makeEnabledSplashScreenThatIntercepts(oz); splashScreenList.add(expectedSplashScreenActivity); when(activityBeansCache.getSplashScreens()).thenReturn(splashScreenList); SplashScreenActivity splashScreenActivity = activityManager.getSplashScreenInterceptor(kansas); assertSame(expectedSplashScreenActivity, splashScreenActivity); verify(splashScreenActivity, times(1)).onStartup(kansas); verify(nonExpectedSplashScreenActivity, never()).onStartup(any(PlaceRequest.class)); }
when(activityManager.getSplashScreenInterceptor(perspectivePlace)).thenReturn(splashScreenActivity); when(perspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(splashScreenActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); never()).onStartup(any(PlaceRequest.class)); inOrder.verify(splashScreenActivity).onOpen(); inOrder.verify(newSplashScreenActiveEvent).fire(any(NewSplashScreenActiveEvent.class));
private SplashScreenActivity makeSplashScreenThatIntercepts(final PlaceRequest place, final boolean enabled) { String splashActivityName = place.getIdentifier() + "!Splash"; SplashScreenActivity splashScreenActivity = mock(SplashScreenActivity.class); when(splashScreenActivity.isEnabled()).thenReturn(enabled); when(splashScreenActivity.intercept(place)).thenReturn(true); when(splashScreenActivity.getPlace()).thenReturn(new DefaultPlaceRequest(splashActivityName)); makeSingletonBean(SplashScreenActivity.class, splashScreenActivity); return splashScreenActivity; }