Search in sources :

Example 31 with State

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);
        }
    }
}
Also used : State(org.eclipse.smarthome.core.types.State) HashSet(java.util.HashSet)

Example 32 with State

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());
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 33 with State

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());
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 34 with State

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);
}
Also used : State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 35 with 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);
}
Also used : State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Aggregations

State (org.eclipse.smarthome.core.types.State)130 Test (org.junit.Test)59 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)23 PercentType (org.eclipse.smarthome.core.library.types.PercentType)22 Item (org.eclipse.smarthome.core.items.Item)21 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)19 Temperature (javax.measure.quantity.Temperature)18 StringType (org.eclipse.smarthome.core.library.types.StringType)18 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)17 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)15 HSBType (org.eclipse.smarthome.core.library.types.HSBType)15 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)15 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)13 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)13 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)12 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)11 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)10 RawType (org.eclipse.smarthome.core.library.types.RawType)10 Pressure (javax.measure.quantity.Pressure)9 GroupItem (org.eclipse.smarthome.core.items.GroupItem)8