diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmableStateTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmableStateTests.java new file mode 100644 index 0000000..87bd181 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmableStateTests.java @@ -0,0 +1,38 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableState; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Dimmable State Tests") +public class DimmableStateTests { + + private DimmableState dimmableState; + + @BeforeEach + public void createDimmableState() { + dimmableState = new DimmableState<>(); + } + + @Test + @DisplayName("get and set intensity") + public void getAndSetIntensity() { + this.dimmableState.setIntensity(20); + assertEquals(20, this.dimmableState.getIntensity()); + } + + @Test + @DisplayName("apply") + public void apply() { + DimmableLight d = new DimmableLight(); + d.setIntensity(45); + this.dimmableState.setDevice(d); + this.dimmableState.setIntensity(30); + this.dimmableState.apply(); + assertEquals(30, this.dimmableState.getDevice().getIntensity()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmerTests.java new file mode 100644 index 0000000..b3971b8 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/DimmerTests.java @@ -0,0 +1,44 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Dimmer Tests") +public class DimmerTests { + + private KnobDimmer dimmer; + + @BeforeEach + public void createDimmer() { + dimmer = new KnobDimmer(); + } + + @Test + @DisplayName("connect true") + public void connectTrue() { + DimmableLight d = new DimmableLight(); + dimmer.connect(d, true); + + assertTrue(d.getDimmers().contains((this.dimmer))); + + assertTrue((this.dimmer.getOutputs().contains(d))); + } + + @Test + @DisplayName("connect off") + public void connectOff() { + DimmableLight d = new DimmableLight(); + d.getDimmers().add(this.dimmer); + dimmer.getOutputs().add(d); + dimmer.connect(d, false); + + assertFalse(d.getDimmers().contains((this.dimmer))); + + assertFalse((this.dimmer.getOutputs().contains(d))); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/MotionSensorTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/MotionSensorTests.java new file mode 100644 index 0000000..9a547e0 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/MotionSensorTests.java @@ -0,0 +1,26 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensor; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Motion Sensor Tests") +public class MotionSensorTests { + + private MotionSensor motionSensor; + + @BeforeEach + public void createMotionSensor() { + motionSensor = new MotionSensor(); + } + + @Test + @DisplayName("set and get detected") + public void setAndGetDetected() { + this.motionSensor.setDetected(true); + assertTrue(this.motionSensor.isDetected()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeConditionTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeConditionTests.java new file mode 100644 index 0000000..354d6da --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeConditionTests.java @@ -0,0 +1,61 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition.Operator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("RAnge Condition Tests") +public class RangeConditionTests { + + private RangeCondition rangeCondition; + + @BeforeEach + public void creteRangeCondition() { + this.rangeCondition = new RangeCondition(); + } + + @Test + @DisplayName("set and get operator") + public void setAndGetOperator() { + rangeCondition.setOperator(RangeCondition.Operator.EQUAL); + + assertEquals(RangeCondition.Operator.EQUAL, rangeCondition.getOperator()); + } + + @Test + @DisplayName("set and get range") + public void setAndGetRange() { + rangeCondition.setRange(20.5); + + assertEquals(20.5, rangeCondition.getRange()); + } + + @Test + @DisplayName("triggered") + public void triggered() { + DimmableLight d = new DimmableLight(); + d.setIntensity(40); + rangeCondition.setDevice(d); + rangeCondition.setRange(45D); + + rangeCondition.setOperator(RangeCondition.Operator.EQUAL); + assertFalse(rangeCondition.triggered()); + + rangeCondition.setOperator(RangeCondition.Operator.LESS); + assertTrue(rangeCondition.triggered()); + + rangeCondition.setOperator(Operator.GREATER); + assertFalse(rangeCondition.triggered()); + + rangeCondition.setOperator(Operator.LESS_EQUAL); + assertTrue(rangeCondition.triggered()); + + rangeCondition.setOperator(Operator.GREATER_EQUAL); + assertFalse(rangeCondition.triggered()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeTriggerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeTriggerTests.java new file mode 100644 index 0000000..6dda510 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/RangeTriggerTests.java @@ -0,0 +1,62 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Range Trigger Tests") +public class RangeTriggerTests { + + private RangeTrigger rangeTrigger; + + @BeforeEach + public void createRangeTrigger() { + this.rangeTrigger = new RangeTrigger(); + } + + @Test + @DisplayName("set and get operator") + public void setAndGetOperator() { + rangeTrigger.setOperator(RangeTrigger.Operator.EQUAL); + + assertEquals(RangeTrigger.Operator.EQUAL, rangeTrigger.getOperator()); + } + + @Test + @DisplayName("set and get range") + public void setAndGetRange() { + rangeTrigger.setRange(20.5); + + assertEquals(20.5, rangeTrigger.getRange()); + } + + @Test + @DisplayName("triggered") + public void triggered() { + DimmableLight d = new DimmableLight(); + d.setIntensity(40); + rangeTrigger.setDevice(d); + rangeTrigger.setRange(45D); + + rangeTrigger.setOperator(RangeTrigger.Operator.EQUAL); + assertFalse(rangeTrigger.triggered()); + + rangeTrigger.setOperator(RangeTrigger.Operator.LESS); + assertTrue(rangeTrigger.triggered()); + + rangeTrigger.setOperator(RangeTrigger.Operator.GREATER); + assertFalse(rangeTrigger.triggered()); + + rangeTrigger.setOperator(RangeTrigger.Operator.LESS_EQUAL); + assertTrue(rangeTrigger.triggered()); + + rangeTrigger.setOperator(RangeTrigger.Operator.GREATER_EQUAL); + assertFalse(rangeTrigger.triggered()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/ScenePriorityTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/ScenePriorityTests.java new file mode 100644 index 0000000..6d27fbf --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/ScenePriorityTests.java @@ -0,0 +1,43 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Scene Priority Tests") +public class ScenePriorityTests { + + private ScenePriority scenePriority; + + @BeforeEach + public void scenePriorityCreate() { + this.scenePriority = new ScenePriority(); + } + + @Test + @DisplayName("get and set automation id") + public void getAndSetAutomationId() { + scenePriority.setAutomationId(20L); + + assertEquals(20, scenePriority.getAutomationId()); + } + + @Test + @DisplayName("get and set scene id") + public void getAndSetSceneId() { + scenePriority.setSceneId(20L); + + assertEquals(20, scenePriority.getSceneId()); + } + + @Test + @DisplayName("get and set priority") + public void getAndSetPriority() { + scenePriority.setPriority(20); + + assertEquals(20, scenePriority.getPriority()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SceneTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SceneTests.java new file mode 100644 index 0000000..28c6f84 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SceneTests.java @@ -0,0 +1,52 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Scene; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Scene Tests") +public class SceneTests { + + private Scene scene; + + @BeforeEach + public void createScene() { + this.scene = new Scene(); + } + + @Test + @DisplayName("get and set id") + public void getAndSetId() { + scene.setId(20L); + + assertEquals(20, scene.getId()); + } + + @Test + @DisplayName("get and set user id") + public void getAndSetUserId() { + scene.setUserId(20L); + + assertEquals(20, scene.getUserId()); + } + + @Test + @DisplayName("get and set name") + public void getAndSetName() { + scene.setName("ciao mamma"); + + assertEquals("ciao mamma", scene.getName()); + } + + @Test + @DisplayName("get access enabled") + public void accessEnabled() { + scene.setGuestAccessEnabled(true); + + assertTrue(scene.isGuestAccessEnabled()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SecurityCameraTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SecurityCameraTests.java new file mode 100644 index 0000000..a9ed512 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SecurityCameraTests.java @@ -0,0 +1,44 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SecurityCamera; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Security Camera Tests") +public class SecurityCameraTests { + + private SecurityCamera securityCamera; + + @BeforeEach + public void createSecurityCamera() { + securityCamera = new SecurityCamera(); + } + + @Test + @DisplayName("get and set Path") + public void getAndSetPath() { + securityCamera.setPath("ciao mamma"); + + assertEquals("ciao mamma", securityCamera.getPath()); + } + + @Test + @DisplayName("get and set On") + public void getAndSetOn() { + securityCamera.setOn(true); + + assertTrue(securityCamera.isOn()); + } + + @Test + @DisplayName("trigger state") + public void triggerState() { + + securityCamera.setOn(true); + + assertTrue(securityCamera.readTriggerState()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SensorTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SensorTests.java new file mode 100644 index 0000000..0326d70 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SensorTests.java @@ -0,0 +1,46 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor.SensorType; +import java.math.BigDecimal; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Sensor Tests") +public class SensorTests { + + Sensor sensor; + + @BeforeEach + public void createSensor() { + this.sensor = new Sensor(); + } + + @Test + @DisplayName("get and set sensor") + public void getAndSetSensor() { + sensor.setSensor(SensorType.LIGHT); + + assertEquals(SensorType.LIGHT, sensor.getSensor()); + } + + @Test + @DisplayName("get and set value") + public void getAndSetValue() { + sensor.setValue(new BigDecimal(40)); + + assertEquals(new BigDecimal(40), sensor.getValue()); + } + + @Test + @DisplayName("to String") + public void toStringTest() { + sensor.setValue(new BigDecimal(40)); + sensor.setSensor(SensorType.LIGHT); + + assertEquals("Sensor{value=40, sensor=LIGHT}", sensor.toString()); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/StateTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/StateTests.java new file mode 100644 index 0000000..85dc695 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/StateTests.java @@ -0,0 +1,58 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableState; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Scene; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Curtains tests") +public class StateTests { + + private DimmableState state; + + @BeforeEach + public void createState() { + this.state = new DimmableState<>(); + } + + @Test + @DisplayName("get and set id") + public void getAndSetId() { + this.state.setId(20); + assertEquals(20, this.state.getId()); + } + + @Test + @DisplayName("get and set device") + public void getAndSetDevice() { + DimmableLight d = new DimmableLight(); + this.state.setDevice(d); + assertEquals(d, this.state.getDevice()); + } + + @Test + @DisplayName("get and set device id") + public void getAndSetDeviceId() { + this.state.setDeviceId(30L); + assertEquals(30, this.state.getDeviceId()); + } + + @Test + @DisplayName("get and set scene") + public void getAndSetScene() { + Scene s = new Scene(); + this.state.setScene(s); + assertEquals(s, this.state.getScene()); + } + + @Test + @DisplayName("get and set sceneId") + public void getAndSetSceneId() { + this.state.setSceneId(50L); + assertEquals(50, this.state.getSceneId()); + } +}