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()));
}
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()));
}
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()));
}
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;
}
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);
}
Aggregations