JSExporterUtils { public static <T extends Activity> T findActivityIfExists(final SyncBeanManager beanManager, String id, Class<T> activityType) { Iterator<SyncBeanDef> existentActivities = beanManager.lookupBeans(id).iterator(); while (existentActivities.hasNext()) { Object existentActivity = existentActivities.next().getInstance(); if (activityType.equals(existentActivity.getClass())) { return (T) existentActivity; } } return null; }  static T findActivityIfExists(final SyncBeanManager beanManager,
                                                              String id,
                                                              Class<T> activityType);  }
@Test public void testUpdateExistentActivity() { List<SyncBeanDef> activities = new ArrayList<SyncBeanDef>(); activities.add(createActivityBeanDef(screenActivity)); when(beanManager.lookupBeans(any(String.class))).thenReturn(activities); JSWorkbenchScreenActivity activity = JSExporterUtils.findActivityIfExists(beanManager, screen.getId(), JSWorkbenchScreenActivity.class); assertNotNull(activity); }
@Test public void testTryUpdatingUnexistentActivity() { List<SyncBeanDef> activities = new ArrayList<SyncBeanDef>(); when(beanManager.lookupBeans(any(String.class))).thenReturn(activities); JSWorkbenchScreenActivity activity = JSExporterUtils.findActivityIfExists(beanManager, screen.getId(), JSWorkbenchScreenActivity.class); assertNull(activity); }