aboutsummaryrefslogtreecommitdiff
path: root/test/org
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-08-11 15:06:09 +0500
committerAbyss777 <abyss@fox5.ru>2017-08-11 15:06:09 +0500
commit32a0fee0b092e488662ed29b7b7f1f303ae57e0f (patch)
tree8bfa422fd12567c1fd8cababe9b225a913492f7b /test/org
parent2e459d8d591ee9d3578a38d981e7c1c13eb3c389 (diff)
downloadtrackermap-server-32a0fee0b092e488662ed29b7b7f1f303ae57e0f.tar.gz
trackermap-server-32a0fee0b092e488662ed29b7b7f1f303ae57e0f.tar.bz2
trackermap-server-32a0fee0b092e488662ed29b7b7f1f303ae57e0f.zip
Make Overspeed and Motion events handlers singleton and move some code to function
Diffstat (limited to 'test/org')
-rw-r--r--test/org/traccar/events/MotionEventHandlerTest.java14
-rw-r--r--test/org/traccar/events/OverspeedEventHandlerTest.java17
2 files changed, 18 insertions, 13 deletions
diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java
index 9df573244..6b7b9daee 100644
--- a/test/org/traccar/events/MotionEventHandlerTest.java
+++ b/test/org/traccar/events/MotionEventHandlerTest.java
@@ -28,7 +28,8 @@ public class MotionEventHandlerTest extends BaseTest {
@Test
public void testMotionWithPosition() throws Exception {
- TripsConfig tripsConfig = new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0);
+ MotionEventHandler motionEventHandler = new MotionEventHandler(
+ new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
@@ -43,11 +44,11 @@ public class MotionEventHandlerTest extends BaseTest {
nextPosition.set(Position.KEY_MOTION, true);
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
- Event event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ Event event = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNull(event);
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 600);
- event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ event = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
assertTrue(deviceState.getMotionState());
@@ -57,7 +58,7 @@ public class MotionEventHandlerTest extends BaseTest {
deviceState.setMotionPosition(position);
nextPosition.setTime(date("2017-01-01 00:06:00"));
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
- event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ event = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
assertTrue(deviceState.getMotionState());
@@ -66,7 +67,8 @@ public class MotionEventHandlerTest extends BaseTest {
@Test
public void testMotionWithStatus() throws Exception {
- TripsConfig tripsConfig = new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0);
+ MotionEventHandler motionEventHandler = new MotionEventHandler(
+ new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0));
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 360000));
@@ -75,7 +77,7 @@ public class MotionEventHandlerTest extends BaseTest {
deviceState.setMotionState(false);
deviceState.setMotionPosition(position);
- Event event = MotionEventHandler.updateMotionState(deviceState, tripsConfig);
+ Event event = motionEventHandler.updateMotionState(deviceState);
assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
diff --git a/test/org/traccar/events/OverspeedEventHandlerTest.java b/test/org/traccar/events/OverspeedEventHandlerTest.java
index eae0917c0..48d7445ff 100644
--- a/test/org/traccar/events/OverspeedEventHandlerTest.java
+++ b/test/org/traccar/events/OverspeedEventHandlerTest.java
@@ -26,13 +26,15 @@ public class OverspeedEventHandlerTest extends BaseTest {
}
private void testOverspeedWithPosition(boolean notRepeat) throws Exception {
+ OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat);
+
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
position.setSpeed(50);
DeviceState deviceState = new DeviceState();
deviceState.setOverspeedState(false);
- Event event = OverspeedEventHandler.updateOverspeedState(deviceState, position, 40, 15000, notRepeat);
+ Event event = overspeedEventHandler.updateOverspeedState(deviceState, position, 40);
assertNull(event);
assertFalse(deviceState.getOverspeedState());
assertEquals(position, deviceState.getOverspeedPosition());
@@ -41,12 +43,12 @@ public class OverspeedEventHandlerTest extends BaseTest {
nextPosition.setTime(date("2017-01-01 00:00:10"));
nextPosition.setSpeed(55);
- event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ event = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40);
assertNull(event);
nextPosition.setTime(date("2017-01-01 00:00:20"));
- event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ event = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40);
assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_OVERSPEED, event.getType());
assertEquals(50, event.getDouble("speed"), 0.1);
@@ -56,7 +58,7 @@ public class OverspeedEventHandlerTest extends BaseTest {
assertNull(deviceState.getOverspeedPosition());
nextPosition.setTime(date("2017-01-01 00:00:30"));
- event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ event = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40);
assertNull(event);
assertEquals(notRepeat, deviceState.getOverspeedState());
@@ -69,13 +71,15 @@ public class OverspeedEventHandlerTest extends BaseTest {
nextPosition.setTime(date("2017-01-01 00:00:40"));
nextPosition.setSpeed(30);
- event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ event = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40);
assertNull(event);
assertFalse(deviceState.getOverspeedState());
assertNull(deviceState.getOverspeedPosition());
}
private void testOverspeedWithStatus(boolean notRepeat) throws Exception {
+ OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat);
+
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 30000));
position.setSpeed(50);
@@ -83,12 +87,11 @@ public class OverspeedEventHandlerTest extends BaseTest {
deviceState.setOverspeedState(false);
deviceState.setOverspeedPosition(position);
- Event event = OverspeedEventHandler.updateOverspeedState(deviceState, 40, 15000, notRepeat);
+ Event event = overspeedEventHandler.updateOverspeedState(deviceState, 40);
assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_OVERSPEED, event.getType());
assertEquals(notRepeat, deviceState.getOverspeedState());
-
}
@Test