Moved find device to its own utility method, and added a specific equals method and reworked some test.
This commit is contained in:
parent
7e8938c38c
commit
c7e286f51e
166 changed files with 618 additions and 374 deletions
|
|
@ -92,6 +92,11 @@ public class EventControllerManagerTest {
|
|||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestEvent2 implements HalEventConfig {
|
||||
|
|
@ -105,6 +110,11 @@ public class EventControllerManagerTest {
|
|||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestController implements HalEventController {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,11 @@ public class SensorControllerManagerTest {
|
|||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestSensor2 implements HalSensorConfig {
|
||||
|
|
@ -127,6 +132,11 @@ public class SensorControllerManagerTest {
|
|||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return HumiditySensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestController implements HalSensorController {
|
||||
|
|
|
|||
45
hal-core/test/se/hal/test/TestDeviceConfig.java
Normal file
45
hal-core/test/se/hal/test/TestDeviceConfig.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package se.hal.test;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
/**
|
||||
* A dymmy device config class
|
||||
*/
|
||||
public class TestDeviceConfig implements HalSensorConfig, HalEventConfig {
|
||||
|
||||
private String id;
|
||||
|
||||
|
||||
public TestDeviceConfig(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDataInterval() {
|
||||
return 60 * 1000; // 1 min
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() {
|
||||
return AggregationMethod.AVERAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TestDeviceConfig)
|
||||
return id.equals(((TestDeviceConfig) obj).id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
31
hal-core/test/se/hal/util/HalDeviceUtilTest.java
Normal file
31
hal-core/test/se/hal/util/HalDeviceUtilTest.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package se.hal.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.test.TestDeviceConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HalDeviceUtilTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testFindDevice() {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
Event device = new Event();
|
||||
device.setDeviceConfig(new TestDeviceConfig("not test"));
|
||||
eventList.add(device);
|
||||
|
||||
Event device2 = new Event();
|
||||
device2.setDeviceConfig(new TestDeviceConfig("not test"));
|
||||
eventList.add(device2);
|
||||
|
||||
Event expectedDevice = new Event();
|
||||
expectedDevice.setDeviceConfig(new TestDeviceConfig("test"));
|
||||
eventList.add(expectedDevice);
|
||||
|
||||
assertEquals(expectedDevice, HalDeviceUtil.findDevice(new TestDeviceConfig("test"), eventList));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue