diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/PageChangeListener.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/PageChangeListener.java index 0728df1b118..059b8ee7c00 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/PageChangeListener.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/PageChangeListener.java @@ -193,12 +193,10 @@ private Set constructSitemapEvents(Item item, State state, List children = itemUIRegistry.getChildren(widget); - PageDTO pageBean = createPageBean(sitemapName, itemUIRegistry.getLabel(pageWidget).label, + PageDTO pageBean = createPageBean(sitemapName, itemUIRegistry.getLabel(pageWidget), itemUIRegistry.getCategory(pageWidget), pageId, children, false, isLeaf(children), uri, locale, timeout, includeHidden); EObject parentPage = pageWidget.eContainer(); @@ -521,17 +521,14 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null logger.debug("{}", e.getMessage()); } } - - ItemUIRegistry.WidgetLabelWithSource label = itemUIRegistry.getLabel(widget); - bean.widgetId = widgetId; bean.icon = itemUIRegistry.getCategory(widget); bean.staticIcon = widget.getStaticIcon() != null; bean.labelcolor = convertItemValueColor(itemUIRegistry.getLabelColor(widget), itemState); bean.valuecolor = convertItemValueColor(itemUIRegistry.getValueColor(widget), itemState); bean.iconcolor = convertItemValueColor(itemUIRegistry.getIconColor(widget), itemState); - bean.label = label.label; - bean.labelSource = label.source.toString(); + bean.label = itemUIRegistry.getLabel(widget); + bean.labelSource = itemUIRegistry.getLabelSource(widget).toString(); bean.pattern = itemUIRegistry.getFormatPattern(widget); bean.unit = itemUIRegistry.getUnitForWidget(widget); bean.type = widget.eClass().getName(); @@ -549,7 +546,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null } } else if (!children.isEmpty()) { String pageName = itemUIRegistry.getWidgetId(linkableWidget); - bean.linkedPage = createPageBean(sitemapName, itemUIRegistry.getLabel(widget).label, + bean.linkedPage = createPageBean(sitemapName, itemUIRegistry.getLabel(widget), itemUIRegistry.getCategory(widget), pageName, drillDown ? children : null, drillDown, isLeaf(children), uri, locale, false, evenIfHidden); } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java index 3d8a3cedae8..13af7c6ac08 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java @@ -57,7 +57,6 @@ import org.openhab.core.types.State; import org.openhab.core.ui.items.ItemUIRegistry; import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelSource; -import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelWithSource; /** * Test aspects of the {@link SitemapResource}. @@ -306,8 +305,8 @@ private void configureItemUIRegistry(State state1, State state2) throws ItemNotF when(itemUIRegistryMock.getWidgetId(widgets.get(0))).thenReturn(WIDGET1_ID); when(itemUIRegistryMock.getCategory(widgets.get(0))).thenReturn(""); - when(itemUIRegistryMock.getLabel(widgets.get(0))) - .thenReturn(new WidgetLabelWithSource(WIDGET1_LABEL, WidgetLabelSource.SITEMAP_WIDGET)); + when(itemUIRegistryMock.getLabel(widgets.get(0))).thenReturn(WIDGET1_LABEL); + when(itemUIRegistryMock.getLabelSource(widgets.get(0))).thenReturn(WidgetLabelSource.SITEMAP_WIDGET); when(itemUIRegistryMock.getVisiblity(widgets.get(0))).thenReturn(true); when(itemUIRegistryMock.getLabelColor(widgets.get(0))).thenReturn("GREEN"); when(itemUIRegistryMock.getValueColor(widgets.get(0))).thenReturn("BLUE"); @@ -316,8 +315,8 @@ private void configureItemUIRegistry(State state1, State state2) throws ItemNotF when(itemUIRegistryMock.getWidgetId(widgets.get(1))).thenReturn(WIDGET2_ID); when(itemUIRegistryMock.getCategory(widgets.get(1))).thenReturn(""); - when(itemUIRegistryMock.getLabel(widgets.get(1))) - .thenReturn(new WidgetLabelWithSource(ITEM_LABEL, WidgetLabelSource.ITEM_LABEL)); + when(itemUIRegistryMock.getLabel(widgets.get(1))).thenReturn(ITEM_LABEL); + when(itemUIRegistryMock.getLabelSource(widgets.get(1))).thenReturn(WidgetLabelSource.ITEM_LABEL); when(itemUIRegistryMock.getVisiblity(widgets.get(1))).thenReturn(true); when(itemUIRegistryMock.getLabelColor(widgets.get(1))).thenReturn(null); when(itemUIRegistryMock.getValueColor(widgets.get(1))).thenReturn(null); diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java index 98b9dcf95b0..3af6e7e1ab9 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java @@ -140,6 +140,16 @@ public class ItemUIRegistryImpl implements ItemUIRegistry { private String groupMembersSorting = DEFAULT_SORTING; + private static class WidgetLabelWithSource { + public final String label; + public final WidgetLabelSource source; + + public WidgetLabelWithSource(String l, WidgetLabelSource s) { + label = l; + source = s; + } + } + @Activate public ItemUIRegistryImpl(@Reference ItemRegistry itemRegistry) { this.itemRegistry = itemRegistry; @@ -322,14 +332,12 @@ private Switch createPlayerButtons() { } @Override - public @Nullable WidgetLabelWithSource getLabel(Widget w) { - WidgetLabelWithSource labelWithSource = getLabelFromWidget(w); - String label = labelWithSource.label; - final WidgetLabelSource source = labelWithSource.source; + public @Nullable String getLabel(Widget w) { + String label = getLabelFromWidget(w).label; String itemName = w.getItem(); if (itemName == null || itemName.isBlank()) { - return transform(label, source, true, null); + return transform(label, true, null); } String labelMappedOption = null; @@ -465,7 +473,12 @@ private Switch createPlayerButtons() { } } - return transform(label, source, considerTransform, labelMappedOption); + return transform(label, considerTransform, labelMappedOption); + } + + @Override + public WidgetLabelSource getLabelSource(Widget w) { + return getLabelFromWidget(w).source; } private QuantityType convertStateToWidgetUnit(QuantityType quantityState, Widget w) { @@ -602,8 +615,7 @@ private String insertInLabel(String label, Object o) { * If the value does not start with the call to a transformation service, * we return the label with the mapped option value if provided (not null). */ - private WidgetLabelWithSource transform(String label, WidgetLabelSource source, boolean matchTransform, - @Nullable String labelMappedOption) { + private String transform(String label, boolean matchTransform, @Nullable String labelMappedOption) { String ret = label; String formatPattern = getFormatPattern(label); if (formatPattern != null) { @@ -638,7 +650,7 @@ private WidgetLabelWithSource transform(String label, WidgetLabelSource source, ret = labelMappedOption; } } - return new WidgetLabelWithSource(ret, source); + return ret; } @Override diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/items/ItemUIRegistry.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/items/ItemUIRegistry.java index 7a05452b2d6..7083988e47f 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/items/ItemUIRegistry.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/items/ItemUIRegistry.java @@ -46,16 +46,6 @@ public enum WidgetLabelSource { NONE }; - public static class WidgetLabelWithSource { - public final String label; - public final WidgetLabelSource source; - - public WidgetLabelWithSource(String l, WidgetLabelSource s) { - label = l; - source = s; - } - } - /** * Retrieves the label for a widget. * @@ -68,10 +58,18 @@ public WidgetLabelWithSource(String l, WidgetLabelSource s) { * current value of the item and padded by a "" element. * * @param w the widget to retrieve the label for - * @return the label to use for the widget, together with its source + * @return the label to use for the widget */ @Nullable - WidgetLabelWithSource getLabel(Widget w); + String getLabel(Widget w); + + /** + * Retrieves the label source for a widget. + * + * @param w the widget to retrieve the label source for + * @return the source the widget label is taken from + */ + WidgetLabelSource getLabelSource(Widget w); /** * Retrieves the category for a widget. diff --git a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java index 6b0e34094bd..34b8266dc8a 100644 --- a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java +++ b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java @@ -81,7 +81,6 @@ import org.openhab.core.types.util.UnitUtils; import org.openhab.core.ui.items.ItemUIProvider; import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelSource; -import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelWithSource; /** * @author Kai Kreuzer - Initial contribution @@ -117,9 +116,8 @@ public void getLabelPlainLabel() { String testLabel = "This is a plain text"; when(widgetMock.getLabel()).thenReturn(testLabel); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals(testLabel, result.label); - assertEquals(WidgetLabelSource.SITEMAP_WIDGET, result.source); + assertEquals(testLabel, uiRegistry.getLabel(widgetMock)); + assertEquals(WidgetLabelSource.SITEMAP_WIDGET, uiRegistry.getLabelSource(widgetMock)); } @Test @@ -127,8 +125,8 @@ public void getLabelLabelWithStaticValue() { String testLabel = "Label [value]"; when(widgetMock.getLabel()).thenReturn(testLabel); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [value]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [value]", label); } @Test @@ -137,8 +135,8 @@ public void getLabelLabelWithStringValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [State]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [State]", label); } @Test @@ -147,8 +145,8 @@ public void getLabelLabelWithStringValueFunction() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new StringType("foo(x):y")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [foo(x):y]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [foo(x):y]", label); } @Test @@ -160,8 +158,8 @@ public void getLabelLabelWithoutPatterAndIntegerValue() { when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20)); when(itemMock.getStateDescription()) .thenReturn(StateDescriptionFragmentBuilder.create().withPattern("%d").build().toStateDescription()); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [20]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [20]", label); } @Test @@ -173,8 +171,8 @@ public void getLabelLabelWithoutPatterAndFractionalDigitsValue() { when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20.5)); when(itemMock.getStateDescription()) .thenReturn(StateDescriptionFragmentBuilder.create().withPattern("%d").build().toStateDescription()); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [21]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [21]", label); } @Test @@ -184,8 +182,8 @@ public void getLabelLabelWithIntegerValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(20)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [20]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [20]", label); } @Test @@ -195,8 +193,8 @@ public void getLabelLabelWithFractionalDigitsValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(20.5)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20.5)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [21]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [21]", label); } @Test @@ -206,8 +204,8 @@ public void getLabelLabelWithIntegerValueAndWidth() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(20)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [ 20]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [ 20]", label); } @Test @@ -217,8 +215,8 @@ public void getLabelLabelWithHexValueAndWidth() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(20)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [ 14]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [ 14]", label); } @Test @@ -228,8 +226,8 @@ public void getLabelLabelWithDecimalValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(10f / 3f)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(10f / 3f)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3" + SEP + "333]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3" + SEP + "333]", label); } @Test @@ -238,8 +236,8 @@ public void getLabelLabelWithDecimalValueAndUnitUpdatedWithQuantityType() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " °C")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3" + SEP + "333 °C]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3" + SEP + "333 °C]", label); } @Test @@ -248,8 +246,8 @@ public void getLabelLabelWithDecimalValueAndUnitUpdatedWithDecimalType() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(10f / 3f)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3" + SEP + "333]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3" + SEP + "333]", label); } @Test @@ -258,8 +256,8 @@ public void getLabelLabelWithDecimalValueAndUnit2() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " °C")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3 °C]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3 °C]", label); } @Test @@ -268,8 +266,8 @@ public void getLabelLabelWithDecimalValueAndUnit3() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3 %]", label); } @Test @@ -278,8 +276,8 @@ public void getLabelLabelWithDecimalValueAndUnit4() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3 %]", label); } @Test @@ -288,8 +286,8 @@ public void getLabelLabelWithDecimalValueAndUnit5() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("33 %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [33 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [33 %]", label); } @Test @@ -298,8 +296,8 @@ public void getLabelLabelWithFractionalDigitsValueAndUnit5() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3 %]", label); } @Test @@ -308,8 +306,8 @@ public void getLabelLabelWithDecimalValueAndUnit6() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3 %]", label); } @Test @@ -318,8 +316,8 @@ public void getLabelLabelWithDecimalValueAndUnit7() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("33 %")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [33 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [33 %]", label); } @Test @@ -328,8 +326,8 @@ public void getLabelLabelWithDecimalValueAndUnitConversion() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new QuantityType<>("22 °C")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [71" + SEP + "60 °F]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [71" + SEP + "60 °F]", label); } @Test @@ -339,8 +337,8 @@ public void getLabelLabelWithPercent() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DecimalType(10f / 3f)); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(10f / 3f)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [3" + SEP + "3 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [3" + SEP + "3 %]", label); } @Test @@ -349,8 +347,8 @@ public void getLabelLabelWithPercentType() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new PercentType(42)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [42 %]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [42 %]", label); } @Test @@ -359,20 +357,20 @@ public void getLabelLabelWithDate() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [01.06.2011]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [01.06.2011]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00Z")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [31.05.2011]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [31.05.2011]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00+02")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [31.05.2011]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [31.05.2011]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00-06")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [01.06.2011]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [01.06.2011]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00-07")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [01.06.2011]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [01.06.2011]", label); } @Test @@ -385,20 +383,20 @@ public void getLabelLabelWithZonedDate() throws ItemNotFoundException { when(w.getItem()).thenReturn(ITEM_NAME); when(registryMock.getItem(ITEM_NAME)).thenReturn(item); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00")); - WidgetLabelWithSource result = uiRegistry.getLabel(w); - assertEquals("Label [01.06.2011]", result.label); + String label = uiRegistry.getLabel(w); + assertEquals("Label [01.06.2011]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00Z")); - result = uiRegistry.getLabel(w); - assertEquals("Label [31.05.2011]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [31.05.2011]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00+02")); - result = uiRegistry.getLabel(w); - assertEquals("Label [31.05.2011]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [31.05.2011]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00-06")); - result = uiRegistry.getLabel(w); - assertEquals("Label [01.06.2011]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [01.06.2011]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00-07")); - result = uiRegistry.getLabel(w); - assertEquals("Label [01.06.2011]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [01.06.2011]", label); } @Test @@ -407,20 +405,20 @@ public void getLabelLabelWithTime() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [15:30:59]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [15:30:59]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59Z")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [09:30:59]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [09:30:59]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59+02")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [07:30:59]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [07:30:59]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59-06")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [15:30:59]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [15:30:59]", label); when(itemMock.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59-07")); - result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [16:30:59]", result.label); + label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [16:30:59]", label); } @Test @@ -433,35 +431,33 @@ public void getLabelLabelWithZonedTime() throws ItemNotFoundException { when(w.getItem()).thenReturn(ITEM_NAME); when(registryMock.getItem(ITEM_NAME)).thenReturn(item); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59")); - WidgetLabelWithSource result = uiRegistry.getLabel(w); - assertEquals("Label [15:30:59]", result.label); + String label = uiRegistry.getLabel(w); + assertEquals("Label [15:30:59]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59Z")); - result = uiRegistry.getLabel(w); - assertEquals("Label [09:30:59]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [09:30:59]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59+02")); - result = uiRegistry.getLabel(w); - assertEquals("Label [07:30:59]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [07:30:59]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59-06")); - result = uiRegistry.getLabel(w); - assertEquals("Label [15:30:59]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [15:30:59]", label); when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59-07")); - result = uiRegistry.getLabel(w); - assertEquals("Label [16:30:59]", result.label); + label = uiRegistry.getLabel(w); + assertEquals("Label [16:30:59]", label); } @Test public void getLabelWidgetWithoutLabelAndItem() { Widget w = mock(Widget.class); - WidgetLabelWithSource result = uiRegistry.getLabel(w); - assertEquals("", result.label); - assertEquals(WidgetLabelSource.NONE, result.source); + assertEquals("", uiRegistry.getLabel(w)); + assertEquals(WidgetLabelSource.NONE, uiRegistry.getLabelSource(w)); } @Test public void getLabelWidgetWithoutLabel() { - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals(ITEM_NAME, result.label); - assertEquals(WidgetLabelSource.ITEM_NAME, result.source); + assertEquals(ITEM_NAME, uiRegistry.getLabel(widgetMock)); + assertEquals(WidgetLabelSource.ITEM_NAME, uiRegistry.getLabelSource(widgetMock)); } @Test @@ -469,9 +465,8 @@ public void getLabelLabelFromUIProvider() { ItemUIProvider provider = mock(ItemUIProvider.class); uiRegistry.addItemUIProvider(provider); when(provider.getLabel(anyString())).thenReturn("ProviderLabel"); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("ProviderLabel", result.label); - assertEquals(WidgetLabelSource.ITEM_LABEL, result.source); + assertEquals("ProviderLabel", uiRegistry.getLabel(widgetMock)); + assertEquals(WidgetLabelSource.ITEM_LABEL, uiRegistry.getLabelSource(widgetMock)); uiRegistry.removeItemUIProvider(provider); } @@ -481,8 +476,8 @@ public void getLabelLabelForUndefinedStringItemState() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(UnDefType.UNDEF); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [-]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [-]", label); } @Test @@ -491,8 +486,8 @@ public void getLabelLabelForUndefinedIntegerItemState() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(UnDefType.UNDEF); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [-]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [-]", label); } @Test @@ -501,8 +496,8 @@ public void getLabelLabelForUndefinedDecimalItemState() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(UnDefType.UNDEF); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [-]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [-]", label); } @Test @@ -511,8 +506,8 @@ public void getLabelLabelForUndefinedDateItemState() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(UnDefType.UNDEF); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [-.-.-]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [-.-.-]", label); } @Test @@ -521,8 +516,8 @@ public void getLabelLabelForUndefinedQuantityItemState() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(UnDefType.UNDEF); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [- -]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [- -]", label); } @Test @@ -532,8 +527,8 @@ public void getLabelItemNotFound() throws ItemNotFoundException { when(widgetMock.getLabel()).thenReturn(testLabel); when(widgetMock.eClass()).thenReturn(SitemapFactory.eINSTANCE.createText().eClass()); when(registryMock.getItem(ITEM_NAME)).thenThrow(new ItemNotFoundException(ITEM_NAME)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [-]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [-]", label); } @Test @@ -542,8 +537,8 @@ public void getLabelLabelWithFunctionValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [State]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [State]", label); } @Test @@ -553,8 +548,8 @@ public void getLabelGroupLabelWithValue() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getState()).thenReturn(OnOffType.ON); when(itemMock.getStateAs(DecimalType.class)).thenReturn(new DecimalType(5)); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [5]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [5]", label); } @Test @@ -645,8 +640,8 @@ public void getLabelLabelWithoutStateDescription() { when(widgetMock.getLabel()).thenReturn(testLabel); when(itemMock.getStateDescription()).thenReturn(null); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label", label); } @Test @@ -658,8 +653,8 @@ public void getLabelLabelWithoutPatternInStateDescription() { when(itemMock.getStateDescription()).thenReturn(stateDescription); when(stateDescription.getPattern()).thenReturn(null); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label", label); } @Test @@ -671,8 +666,8 @@ public void getLabelLabelWithPatternInStateDescription() { when(itemMock.getStateDescription()).thenReturn(stateDescription); when(stateDescription.getPattern()).thenReturn("%s"); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [State]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [State]", label); } @Test @@ -684,8 +679,8 @@ public void getLabelLabelWithEmptyPattern() { when(itemMock.getStateDescription()).thenReturn(stateDescription); when(stateDescription.getPattern()).thenReturn("%s"); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label", label); } @Test @@ -701,8 +696,8 @@ public void getLabelLabelWithMappedOption() { when(stateDescription.getPattern()).thenReturn("%s"); when(stateDescription.getOptions()).thenReturn(options); when(itemMock.getState()).thenReturn(new StringType("State1")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [This is the state 1]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [This is the state 1]", label); } @Test @@ -718,8 +713,8 @@ public void getLabelLabelWithUnmappedOption() { when(stateDescription.getPattern()).thenReturn("%s"); when(stateDescription.getOptions()).thenReturn(options); when(itemMock.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(widgetMock); - assertEquals("Label [State]", result.label); + String label = uiRegistry.getLabel(widgetMock); + assertEquals("Label [State]", label); } @Test @@ -732,8 +727,8 @@ public void getLabelTransformationContainingPercentS() throws ItemNotFoundExcept when(w.getItem()).thenReturn(ITEM_NAME); when(registryMock.getItem(ITEM_NAME)).thenReturn(item); when(item.getState()).thenReturn(new StringType("State")); - WidgetLabelWithSource result = uiRegistry.getLabel(w); - assertEquals("Memory [State]", result.label); + String label = uiRegistry.getLabel(w); + assertEquals("Memory [State]", label); } @Test