aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/reports
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 14:59:09 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 14:59:09 -0700
commit85f04c6d30e11d8b748ea2b431dbeffce1126a65 (patch)
treebef590914d97fb830cf5e15bfea15d021f182af3 /src/test/java/org/traccar/reports
parent0202dbf7258df8cbe8168ddc985e774b1cadf964 (diff)
downloadtrackermap-server-85f04c6d30e11d8b748ea2b431dbeffce1126a65.tar.gz
trackermap-server-85f04c6d30e11d8b748ea2b431dbeffce1126a65.tar.bz2
trackermap-server-85f04c6d30e11d8b748ea2b431dbeffce1126a65.zip
Remove test identity manager
Diffstat (limited to 'src/test/java/org/traccar/reports')
-rw-r--r--src/test/java/org/traccar/reports/ReportUtilsTest.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/test/java/org/traccar/reports/ReportUtilsTest.java b/src/test/java/org/traccar/reports/ReportUtilsTest.java
index deb17ddd2..b27104f76 100644
--- a/src/test/java/org/traccar/reports/ReportUtilsTest.java
+++ b/src/test/java/org/traccar/reports/ReportUtilsTest.java
@@ -4,6 +4,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.text.DateFormat;
import java.text.ParseException;
@@ -17,7 +20,8 @@ import java.util.TimeZone;
import org.junit.Test;
import org.traccar.BaseTest;
-import org.traccar.TestIdentityManager;
+import org.traccar.database.IdentityManager;
+import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.reports.model.StopReport;
import org.traccar.reports.model.TripReport;
@@ -43,6 +47,14 @@ public class ReportUtilsTest extends BaseTest {
return position;
}
+ private IdentityManager mockIdentityManager() {
+ var device = mock(Device.class);
+ when(device.getName()).thenReturn("test");
+ var identityManager = mock(IdentityManager.class);
+ when(identityManager.getById(anyLong())).thenReturn(device);
+ return identityManager;
+ }
+
@Test
public void testCalculateDistance() {
Position startPosition = new Position();
@@ -81,7 +93,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false, false, 0.01);
Collection<TripReport> trips = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, TripReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, TripReport.class);
assertNotNull(trips);
assertFalse(trips.isEmpty());
@@ -96,7 +108,7 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(3000, itemTrip.getDistance(), 0.01);
Collection<StopReport> stops = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(stops);
assertFalse(stops.isEmpty());
@@ -135,7 +147,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, true, false, 0.01);
Collection<TripReport> trips = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, TripReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, TripReport.class);
assertNotNull(trips);
assertFalse(trips.isEmpty());
@@ -150,7 +162,7 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(3000, itemTrip.getDistance(), 0.01);
trips = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, TripReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, TripReport.class);
assertNotNull(trips);
assertFalse(trips.isEmpty());
@@ -165,7 +177,7 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(3000, itemTrip.getDistance(), 0.01);
Collection<StopReport> stops = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(stops);
assertFalse(stops.isEmpty());
@@ -206,7 +218,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false, false, 0.01);
Collection<TripReport> trips = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, TripReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, TripReport.class);
assertNotNull(trips);
assertFalse(trips.isEmpty());
@@ -221,7 +233,7 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(7000, itemTrip.getDistance(), 0.01);
Collection<StopReport> stops = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(stops);
assertFalse(stops.isEmpty());
@@ -256,7 +268,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
@@ -283,7 +295,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
@@ -310,7 +322,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
@@ -337,7 +349,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertTrue(result.isEmpty());
@@ -360,7 +372,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, 900000, false, false, 0.01);
Collection<TripReport> trips = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, TripReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, TripReport.class);
assertNotNull(trips);
assertFalse(trips.isEmpty());
@@ -375,7 +387,7 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(600, itemTrip.getDistance(), 0.01);
Collection<StopReport> stops = ReportUtils.detectTripsAndStops(
- new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
+ mockIdentityManager(), null, data, tripsConfig, false, StopReport.class);
assertNotNull(stops);
assertFalse(stops.isEmpty());