Search in sources :

Example 21 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.

the class StateDescriptionServiceImplTest method testCorrectIsReadOnlyWhenTwoDescriptionProvidersHigherRankingIsNotReadOnly.

@Test
public void testCorrectIsReadOnlyWhenTwoDescriptionProvidersHigherRankingIsNotReadOnly() {
    StateDescription stateDescription1 = new StateDescription(null, null, null, null, false, null);
    StateDescription stateDescription2 = new StateDescription(null, null, null, null, true, null);
    int stateDescriptionProvider1ServiceRanking = -1;
    int stateDescriptionProvider2ServiceRanking = -2;
    StateDescription finalStateDescription = mergeStateDescriptions(stateDescription1, stateDescription2, stateDescriptionProvider1ServiceRanking, stateDescriptionProvider2ServiceRanking);
    assertThat(finalStateDescription.isReadOnly(), is(stateDescription1.isReadOnly()));
}
Also used : StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 22 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.

the class StateDescriptionServiceImplTest method testCorrectOptionsWhenTwoDescriptionProvidersHigherRankingDoesntProvideOptions.

@Test
public void testCorrectOptionsWhenTwoDescriptionProvidersHigherRankingDoesntProvideOptions() {
    StateDescription stateDescription1 = new StateDescription(null, null, null, null, false, Collections.emptyList());
    StateDescription stateDescription2 = new StateDescription(null, null, null, null, false, Arrays.asList(new StateOption("value", "label")));
    int stateDescriptionProvider1ServiceRanking = -1;
    int stateDescriptionProvider2ServiceRanking = -2;
    StateDescription finalStateDescription = mergeStateDescriptions(stateDescription1, stateDescription2, stateDescriptionProvider1ServiceRanking, stateDescriptionProvider2ServiceRanking);
    assertThat(finalStateDescription.getOptions(), is(stateDescription2.getOptions()));
}
Also used : StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 23 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.

the class StateDescriptionServiceImplTest method testCorrectOptionsWhenTwoDescriptionProvidersHigherRankingProvidesOptions.

@Test
public void testCorrectOptionsWhenTwoDescriptionProvidersHigherRankingProvidesOptions() {
    StateDescription stateDescription1 = new StateDescription(null, null, null, null, false, Arrays.asList(new StateOption("value", "label")));
    StateDescription stateDescription2 = new StateDescription(null, null, null, null, false, Collections.emptyList());
    int stateDescriptionProvider1ServiceRanking = -1;
    int stateDescriptionProvider2ServiceRanking = -2;
    StateDescription finalStateDescription = mergeStateDescriptions(stateDescription1, stateDescription2, stateDescriptionProvider1ServiceRanking, stateDescriptionProvider2ServiceRanking);
    assertThat(finalStateDescription.getOptions(), is(stateDescription1.getOptions()));
}
Also used : StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 24 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.

the class StateDescriptionServiceImplTest method mergeStateDescriptions.

private StateDescription mergeStateDescriptions(StateDescription stateDescription1, StateDescription stateDescription2, int stateDescriptionProvider1ServiceRanking, int stateDescriptionProvider2ServiceRanking) {
    StateDescriptionProvider stateDescriptionProvider1 = mock(StateDescriptionProvider.class);
    StateDescriptionProvider stateDescriptionProvider2 = mock(StateDescriptionProvider.class);
    when(stateDescriptionProvider1.getRank()).thenReturn(stateDescriptionProvider1ServiceRanking);
    when(stateDescriptionProvider2.getRank()).thenReturn(stateDescriptionProvider2ServiceRanking);
    when(stateDescriptionProvider1.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription1);
    when(stateDescriptionProvider2.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription2);
    mergingService.addStateDescriptionProvider(stateDescriptionProvider1);
    mergingService.addStateDescriptionProvider(stateDescriptionProvider2);
    item = new NumberItem(ITEM_NAME);
    item.setStateDescriptionService(mergingService);
    StateDescription finalStateDescription = item.getStateDescription();
    return finalStateDescription;
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 25 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithUnmappedOption.

@Test
public void getLabel_labelWithUnmappedOption() throws ItemNotFoundException {
    String testLabel = "Label";
    StateDescription stateDescription = mock(StateDescription.class);
    List<StateOption> options = new ArrayList<>();
    options.add(new StateOption("State0", "This is the state 0"));
    options.add(new StateOption("State1", "This is the state 1"));
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(stateDescription.getOptions()).thenReturn(options);
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [State]", label);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Aggregations

StateDescription (org.eclipse.smarthome.core.types.StateDescription)31 Test (org.junit.Test)15 StateOption (org.eclipse.smarthome.core.types.StateOption)13 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)7 ArrayList (java.util.ArrayList)6 StringType (org.eclipse.smarthome.core.library.types.StringType)6 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)6 BigDecimal (java.math.BigDecimal)4 Item (org.eclipse.smarthome.core.items.Item)4 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)4 StateDescriptionProvider (org.eclipse.smarthome.core.types.StateDescriptionProvider)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 GroupItem (org.eclipse.smarthome.core.items.GroupItem)3 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 StringItem (org.eclipse.smarthome.core.library.items.StringItem)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Before (org.junit.Before)3 Collection (java.util.Collection)2