GroupItemSelectorTrackerUtil { public static Optional<GroupItemSelectorProvider> getGroupItemSelectorProviderOptional(String groupType) { if (_serviceTrackerMap == null) { return Optional.empty(); } GroupItemSelectorProvider groupItemSelectorProvider = _serviceTrackerMap.getService(groupType); if ((groupItemSelectorProvider != null) && groupItemSelectorProvider.isEnabled()) { return Optional.of(groupItemSelectorProvider); } return Optional.empty(); }  static Optional<GroupItemSelectorProvider> getGroupItemSelectorProviderOptional(String groupType); static Set<String> getGroupItemSelectorProviderTypes();  }
@Test public void testGetGroupItemSelectorProviderOptionalWithoutRegisteredGroupItemSelectorProvider() { Optional<GroupItemSelectorProvider> groupItemSelectorProviderOptional = GroupItemSelectorTrackerUtil.getGroupItemSelectorProviderOptional( RandomTestUtil.randomString()); Assert.assertTrue(!groupItemSelectorProviderOptional.isPresent()); }
@Test public void testGetGroupItemSelectorProviderOptionalWithRegisteredGroupItemSelectorProvider() { ReflectionTestUtil.setFieldValue( GroupItemSelectorTrackerUtil.class, "_serviceTrackerMap", new MockServiceTrackerMap( Collections.singletonMap( "test", new MockGroupItemSelectorProvider()))); Optional<GroupItemSelectorProvider> groupItemSelectorProviderOptional = GroupItemSelectorTrackerUtil.getGroupItemSelectorProviderOptional( "test"); Assert.assertTrue(groupItemSelectorProviderOptional.isPresent()); GroupItemSelectorProvider groupItemSelectorProvider = groupItemSelectorProviderOptional.get(); Assert.assertEquals("icon", groupItemSelectorProvider.getIcon()); ReflectionTestUtil.setFieldValue( GroupItemSelectorTrackerUtil.class, "_serviceTrackerMap", null); }