@Override public <T extends Activity> T getActivity(final Class<T> clazz, final PlaceRequest placeRequest) { return getActivity(clazz, placeRequest, true); }
@Override public Activity getActivity(PlaceRequest placeRequest, boolean secure) { return getActivity(Activity.class, placeRequest, secure); }
@Override public Activity getActivity(final PlaceRequest placeRequest) { return getActivity(Activity.class, placeRequest); }
@Override public boolean containsActivity(final PlaceRequest placeRequest) { if (containsCache.containsKey(placeRequest.getIdentifier())) { return containsCache.get(placeRequest.getIdentifier()); } Path path = null; if (placeRequest instanceof PathPlaceRequest) { path = ((PathPlaceRequest) placeRequest).getPath(); if (containsCache.containsKey(path)) { return containsCache.get(path); } } final Activity result = getActivity(placeRequest); containsCache.put(placeRequest.getIdentifier(), result != null); if (path != null) { containsCache.put(path, result != null); } return result != null; }
@Test public void activityBeanShouldBeCreatedOnlyOnceOnGetActivity() throws Exception { activityManager.getActivity(pathPlace); activityManager.getActivity(pathPlace); verify(pathIocBeanSpy, times(1)).getInstance(); }
@Test public void activityBeanShouldBeCreatedOnlyOnceOnGetActivity() throws Exception { activityManager.getActivity(pathPlace); activityManager.getActivity(pathPlace); verify(pathIocBeanSpy, times(1)).getInstance(); }
@Test public void getActivityForActivePlaceRequestShouldReturnActivity() throws Exception { Activity activity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest("activated activity")); assertSame(activatedActivity, activity); }
@Test public void getActivityForActivePlaceRequestShouldReturnActivity() throws Exception { Activity activity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest("activated activity")); assertSame(activatedActivity, activity); }
@Test public void getActivityForInactivePlaceRequestShouldReturnNull() throws Exception { Activity activity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest("non-activated activity")); assertNull(activity); } }
@Test public void getActivityForInactivePlaceRequestShouldReturnNull() throws Exception { Activity activity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest("non-activated activity")); assertNull(activity); } }
@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); }
@Test public void shouldNotAttemptToDestroyRuntimeRegisteredSingletonActivities() throws Exception { abstract class MyPerspectiveActivity implements PerspectiveActivity { } ; final String myPerspectiveId = "myPerspectiveId"; final MyPerspectiveActivity activity = mock(MyPerspectiveActivity.class); when(activity.getIdentifier()).thenReturn(myPerspectiveId); when(activity.getPlace()).thenReturn(new DefaultPlaceRequest(myPerspectiveId)); // note that we're telling the bean manager this bean is of concrete type PerspectiveActivity. // this mirrors what the JavaScript runtime plugin API does. SyncBeanDef<PerspectiveActivity> perspectiveActivityBean = makeSingletonBean(PerspectiveActivity.class, activity, myPerspectiveId); when(activityBeansCache.getActivity(myPerspectiveId)).thenReturn((SyncBeanDef) perspectiveActivityBean); Activity retrievedActivity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest(myPerspectiveId)); activityManager.destroyActivity(retrievedActivity); // it's a singleton, so we should not try to destroy it. verify(iocManager, never()).destroyBean(activity); }
@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); }
@Test public void shouldNotAttemptToDestroyRuntimeRegisteredSingletonActivities() throws Exception { abstract class MyPerspectiveActivity implements PerspectiveActivity { } ; final String myPerspectiveId = "myPerspectiveId"; final MyPerspectiveActivity activity = mock(MyPerspectiveActivity.class); when(activity.getIdentifier()).thenReturn(myPerspectiveId); when(activity.getPlace()).thenReturn(new DefaultPlaceRequest(myPerspectiveId)); // note that we're telling the bean manager this bean is of concrete type PerspectiveActivity. // this mirrors what the JavaScript runtime plugin API does. SyncBeanDef<PerspectiveActivity> perspectiveActivityBean = makeSingletonBean(PerspectiveActivity.class, activity, myPerspectiveId); when(activityBeansCache.getActivity(myPerspectiveId)).thenReturn((SyncBeanDef) perspectiveActivityBean); Activity retrievedActivity = activityManager.getActivity(Activity.class, new DefaultPlaceRequest(myPerspectiveId)); activityManager.destroyActivity(retrievedActivity); // it's a singleton, so we should not try to destroy it. verify(iocManager, never()).destroyBean(activity); }
@Test public void shouldResolvePlaceIdentifierForPathPlaceRequestOnGetActivity() throws Exception { assertEquals(PathPlaceRequest.NULL, pathPlace.getIdentifier()); Activity activity = activityManager.getActivity(pathPlace); assertNotNull(activity); assertEquals(PATH_PLACE_ID, pathPlace.getIdentifier()); assertEquals(pathPlaceActivity, activity); }
@Test public void shouldResolvePlaceIdentifierForPathPlaceRequestOnGetActivity() throws Exception { assertEquals(PathPlaceRequest.NULL, pathPlace.getIdentifier()); Activity activity = activityManager.getActivity(pathPlace); assertNotNull(activity); assertEquals(PATH_PLACE_ID, pathPlace.getIdentifier()); assertEquals(pathPlaceActivity, activity); }