From 8313471a752dc08e5e7a270349e9f03417672b08 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 14 Aug 2017 14:43:17 +0500 Subject: Correct motion state by ignition. --- .../org/traccar/events/MotionEventHandlerTest.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'test/org/traccar/events') diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java index 6b7b9daee..826f4c4e5 100644 --- a/test/org/traccar/events/MotionEventHandlerTest.java +++ b/test/org/traccar/events/MotionEventHandlerTest.java @@ -1,6 +1,7 @@ package org.traccar.events; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -29,7 +30,7 @@ public class MotionEventHandlerTest extends BaseTest { @Test public void testMotionWithPosition() throws Exception { MotionEventHandler motionEventHandler = new MotionEventHandler( - new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0)); + new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, false)); Position position = new Position(); position.setTime(date("2017-01-01 00:00:00")); @@ -68,7 +69,7 @@ public class MotionEventHandlerTest extends BaseTest { @Test public void testMotionWithStatus() throws Exception { MotionEventHandler motionEventHandler = new MotionEventHandler( - new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0)); + new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, false)); Position position = new Position(); position.setTime(new Date(System.currentTimeMillis() - 360000)); @@ -85,4 +86,29 @@ public class MotionEventHandlerTest extends BaseTest { assertNull(deviceState.getMotionPosition()); } + @Test + public void testStopWithPositionIgnition() throws Exception { + MotionEventHandler motionEventHandler = new MotionEventHandler( + new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, true)); + + Position position = new Position(); + position.setTime(date("2017-01-01 00:00:00")); + position.set(Position.KEY_MOTION, false); + position.set(Position.KEY_IGNITION, true); + DeviceState deviceState = new DeviceState(); + deviceState.setMotionState(true); + deviceState.setMotionPosition(position); + + Position nextPosition = new Position(); + nextPosition.setTime(date("2017-01-01 00:02:00")); + nextPosition.set(Position.KEY_MOTION, false); + nextPosition.set(Position.KEY_IGNITION, false); + + Event event = motionEventHandler.updateMotionState(deviceState, nextPosition); + assertNotNull(event); + assertEquals(Event.TYPE_DEVICE_STOPPED, event.getType()); + assertFalse(deviceState.getMotionState()); + assertNull(deviceState.getMotionPosition()); + } + } -- cgit v1.2.3