aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/handler
diff options
context:
space:
mode:
authorjcardus <asklocation.net@gmail.com>2022-10-26 17:11:14 +0100
committerjcardus <asklocation.net@gmail.com>2022-10-26 17:11:14 +0100
commit907e5d1669c154e266383a275c1212baea1bda2a (patch)
tree4fb735b40033de8ae871eebf28a829c5fdf1b977 /src/test/java/org/traccar/handler
parent3c7afdf75c4f3d045c0d51355d6ce62622eb2c4d (diff)
downloadtrackermap-server-907e5d1669c154e266383a275c1212baea1bda2a.tar.gz
trackermap-server-907e5d1669c154e266383a275c1212baea1bda2a.tar.bz2
trackermap-server-907e5d1669c154e266383a275c1212baea1bda2a.zip
added MaintenanceEventHandlerTest
Diffstat (limited to 'src/test/java/org/traccar/handler')
-rw-r--r--src/test/java/org/traccar/handler/events/MaintenanceEventHandlerTest.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/org/traccar/handler/events/MaintenanceEventHandlerTest.java b/src/test/java/org/traccar/handler/events/MaintenanceEventHandlerTest.java
new file mode 100644
index 000000000..aa2d0bbe3
--- /dev/null
+++ b/src/test/java/org/traccar/handler/events/MaintenanceEventHandlerTest.java
@@ -0,0 +1,60 @@
+package org.traccar.handler.events;
+
+import org.junit.Test;
+import org.traccar.BaseTest;
+import org.traccar.model.Maintenance;
+import org.traccar.model.Position;
+import org.traccar.session.cache.CacheManager;
+
+import java.util.Arrays;
+import java.util.Date;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.anyLong;
+
+public class MaintenanceEventHandlerTest extends BaseTest {
+
+ @Test
+ public void testMaintenanceEventHandler() {
+ Position lastPosition = new Position();
+ lastPosition.setDeviceId(1);
+ lastPosition.setFixTime(new Date(0));
+
+ Position position = new Position();
+ position.setDeviceId(1);
+ position.setFixTime(new Date(0));
+
+ var maintenance = mock(Maintenance.class);
+ when(maintenance.getType()).thenReturn(Position.KEY_TOTAL_DISTANCE);
+ var maintenances = Arrays.asList(maintenance);
+
+ var cacheManager = mock(CacheManager.class);
+ when(cacheManager.getDeviceObjects(anyLong(), eq(Maintenance.class))).thenReturn(maintenances);
+ when(cacheManager.getPosition(anyLong())).thenReturn(lastPosition);
+ MaintenanceEventHandler eventHandler = new MaintenanceEventHandler(cacheManager);
+
+ when(maintenance.getStart()).thenReturn(10000.0);
+ when(maintenance.getPeriod()).thenReturn(2000.0);
+
+ lastPosition.set(Position.KEY_TOTAL_DISTANCE, 1999);
+ position.set(Position.KEY_TOTAL_DISTANCE, 2001);
+ assertTrue(eventHandler.analyzePosition(position).isEmpty());
+
+ lastPosition.set(Position.KEY_TOTAL_DISTANCE, 3999);
+ position.set(Position.KEY_TOTAL_DISTANCE, 4001);
+ assertTrue(eventHandler.analyzePosition(position).isEmpty());
+
+ lastPosition.set(Position.KEY_TOTAL_DISTANCE, 9999);
+ position.set(Position.KEY_TOTAL_DISTANCE, 10001);
+ assertTrue(eventHandler.analyzePosition(position).size() == 1);
+
+ lastPosition.set(Position.KEY_TOTAL_DISTANCE, 11999);
+ position.set(Position.KEY_TOTAL_DISTANCE, 12001);
+ assertTrue(eventHandler.analyzePosition(position).size() == 1);
+
+ }
+
+}