use of org.eclipse.smarthome.core.i18n.UnitProvider in project smarthome by eclipse.
the class ItemStateConverterImplTest method numberItemShouldNotConvertUnitsWhereMeasurmentSystemEquals.
@Test
public void numberItemShouldNotConvertUnitsWhereMeasurmentSystemEquals() {
NumberItem item = mock(NumberItem.class);
doReturn(Length.class).when(item).getDimension();
UnitProvider unitProvider = mock(UnitProvider.class);
when(unitProvider.getUnit(Length.class)).thenReturn(SIUnits.METRE);
itemStateConverter.setUnitProvider(unitProvider);
QuantityType<Length> originalState = new QuantityType<>("100 cm");
@SuppressWarnings("unchecked") QuantityType<Length> convertedState = (QuantityType<Length>) itemStateConverter.convertToAcceptedState(originalState, item);
assertThat(convertedState.getUnit(), is(originalState.getUnit()));
}
use of org.eclipse.smarthome.core.i18n.UnitProvider in project smarthome by eclipse.
the class ItemStateConverterImplTest method numberItemWitDimensionShouldConvertToLocaleBasedUnit.
@Test
public void numberItemWitDimensionShouldConvertToLocaleBasedUnit() {
NumberItem item = mock(NumberItem.class);
doReturn(Temperature.class).when(item).getDimension();
UnitProvider unitProvider = mock(UnitProvider.class);
when(unitProvider.getUnit(Temperature.class)).thenReturn(ImperialUnits.FAHRENHEIT);
itemStateConverter.setUnitProvider(unitProvider);
State originalState = new QuantityType<>("12.34 °C");
State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
assertThat(convertedState, is(new QuantityType<>("54.212 °F")));
}
use of org.eclipse.smarthome.core.i18n.UnitProvider in project smarthome by eclipse.
the class NumberItemTest method testSetQuantityTypeUnconverted.
@Test
public void testSetQuantityTypeUnconverted() {
NumberItem item = new NumberItem("Number:Temperature", "test");
UnitProvider unitProvider = mock(UnitProvider.class);
when(unitProvider.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
item.setUnitProvider(unitProvider);
// should not be accepted as valid state
item.setState(new QuantityType<>("10 A"));
assertThat(item.getState(), is(UnDefType.NULL));
}
Aggregations