use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class StateUtil method testAcceptedStates.
public static void testAcceptedStates(GenericItem item) {
HashSet<Class<? extends State>> successfullStates = new HashSet<>();
for (State s : getAllStates()) {
item.setState(s);
if (item.isAcceptedState(item.getAcceptedDataTypes(), s)) {
if (s.equals(UnDefType.NULL)) {
// if we set null, the item should stay null
assertEquals(UnDefType.NULL, item.getState());
} else {
// the state should be set on the item now
assertNotEquals(UnDefType.NULL, item.getState());
successfullStates.add(s.getClass());
}
// reset item
item.setState(UnDefType.NULL);
} else {
assertEquals(UnDefType.NULL, item.getState());
}
}
// test if the item accepts a state that is not in our test state list
for (Class<? extends State> acceptedState : item.getAcceptedDataTypes()) {
if (!successfullStates.contains(acceptedState)) {
fail("Item '" + item.getType() + "' accepts untested state: " + acceptedState);
}
}
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class StringItemTest method setStringType.
@Test
public void setStringType() {
StringItem item = new StringItem("test");
State state = new StringType("foobar");
item.setState(state);
assertEquals(state, item.getState());
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class StringItemTest method setDateTimeTypeType.
@Test
public void setDateTimeTypeType() {
StringItem item = new StringItem("test");
State state = new DateTimeType();
item.setState(state);
assertEquals(state, item.getState());
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class ArithmeticGroupFunctionTest method testOrFunction.
@Test
public void testOrFunction() {
items.add(new TestItem("TestItem1", OpenClosedType.CLOSED));
items.add(new TestItem("TestItem2", UnDefType.UNDEF));
items.add(new TestItem("TestItem3", OpenClosedType.OPEN));
items.add(new TestItem("TestItem4", OpenClosedType.CLOSED));
items.add(new TestItem("TestItem5", UnDefType.UNDEF));
function = new ArithmeticGroupFunction.Or(OpenClosedType.OPEN, OpenClosedType.CLOSED);
State state = function.calculate(items);
assertEquals(OpenClosedType.OPEN, state);
}
use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.
the class ArithmeticGroupFunctionTest method testAndFunction_justsOneItem.
@Test
public void testAndFunction_justsOneItem() {
items.add(new TestItem("TestItem1", UnDefType.UNDEF));
function = new ArithmeticGroupFunction.And(OpenClosedType.OPEN, OpenClosedType.CLOSED);
State state = function.calculate(items);
assertEquals(OpenClosedType.CLOSED, state);
}
Aggregations