ItemUIRegistryImpl implements ItemUIRegistry { @Override public @Nullable String getLabel(String itemName) { for (ItemUIProvider provider : itemUIProviders) { String currentLabel = provider.getLabel(itemName); if (currentLabel != null) { return currentLabel; } } try { Item item = getItem(itemName); if (item.getLabel() != null) { return item.getLabel(); } } catch (ItemNotFoundException e) { } return null; } @Activate  ItemUIRegistryImpl(@Reference ItemRegistry itemRegistry); @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addItemUIProvider(ItemUIProvider itemUIProvider); void removeItemUIProvider(ItemUIProvider itemUIProvider); @Override @Nullable String getCategory(String itemName); @Override @Nullable String getLabel(String itemName); @Override @Nullable Widget getWidget(String itemName); @Override @Nullable Widget getDefaultWidget(@Nullable Class<? extends Item> targetItemType, String itemName); @Override @Nullable String getLabel(Widget w); @Override @Nullable String getCategory(Widget w); @Override @Nullable State getState(Widget w); @Override @Nullable State convertState(Widget w, Item i, State state); @Override @Nullable Widget getWidget(Sitemap sitemap, String id); @Override EList<Widget> getChildren(Sitemap sitemap); @Override EList<Widget> getChildren(LinkableWidget w); @Override @Nullable EObject getParent(Widget w); @Override @Nullable State getItemState(String itemName); @Nullable String getItemCategory(String itemName); @Override Item getItem(String name); @Override Item getItemByPattern(String name); @Override Collection<Item> getItems(); @Override Collection<Item> getItemsOfType(String type); @Override Collection<Item> getItems(String pattern); @Override void addRegistryChangeListener(RegistryChangeListener<Item> listener); @Override void removeRegistryChangeListener(RegistryChangeListener<Item> listener); @Override Collection<Item> getAll(); @Override Stream<Item> stream(); @Override String getWidgetId(Widget widget); @Override @Nullable String getLabelColor(Widget w); @Override @Nullable String getValueColor(Widget w); @Override boolean getVisiblity(Widget w); @Override Collection<Item> getItemsByTag(String... tags); @Override Collection<Item> getItemsByTagAndType(String type, String... tags); @Override Collection<T> getItemsByTag(Class<T> typeFilter, String... tags); @Override Item add(Item element); @Override @Nullable Item update(Item element); @Override @Nullable Item remove(String key); @Override @Nullable Item get(String key); @Override @Nullable Item remove(String itemName, boolean recursive); @Override void addRegistryHook(RegistryHook<Item> hook); @Override void removeRegistryHook(RegistryHook<Item> hook); @Override @Nullable String getUnitForWidget(Widget w); @Override @Nullable State convertStateToLabelUnit(QuantityType<?> state, String label);  }
@Test public void getLabelPlainLabel() { String testLabel = "This is a plain text"; when(widget.getLabel()).thenReturn(testLabel); String label = uiRegistry.getLabel(widget); assertEquals(testLabel, label); }
@Test public void getLabelLabelWithStaticValue() { String testLabel = "Label [value]"; when(widget.getLabel()).thenReturn(testLabel); String label = uiRegistry.getLabel(widget); assertEquals("Label [value]", label); }
@Test public void getLabelWidgetWithoutLabelAndItem() { Widget w = mock(Widget.class); String label = uiRegistry.getLabel(w); assertEquals("", label); }
@Test public void getLabelWidgetWithoutLabel() { String label = uiRegistry.getLabel(widget); assertEquals(ITEM_NAME, label); }