aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/traccar/BaseTest.java9
-rw-r--r--src/test/java/org/traccar/WebDataHandlerTest.java8
-rw-r--r--src/test/java/org/traccar/handler/ComputedAttributesTest.java2
-rw-r--r--src/test/java/org/traccar/reports/ReportUtilsTest.java43
4 files changed, 27 insertions, 35 deletions
diff --git a/src/test/java/org/traccar/BaseTest.java b/src/test/java/org/traccar/BaseTest.java
index 6db568300..c784150dd 100644
--- a/src/test/java/org/traccar/BaseTest.java
+++ b/src/test/java/org/traccar/BaseTest.java
@@ -3,7 +3,6 @@ package org.traccar;
import io.netty.channel.Channel;
import org.traccar.config.Config;
import org.traccar.database.CommandsManager;
-import org.traccar.database.IdentityManager;
import org.traccar.database.MediaManager;
import org.traccar.database.StatisticsManager;
import org.traccar.model.Device;
@@ -14,8 +13,6 @@ import org.traccar.session.cache.CacheManager;
import java.net.SocketAddress;
import java.util.HashSet;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
@@ -29,9 +26,6 @@ public class BaseTest {
decoder.setConfig(config);
var device = mock(Device.class);
when(device.getId()).thenReturn(1L);
- var identityManager = mock(IdentityManager.class);
- when(identityManager.getById(anyLong())).thenReturn(device);
- decoder.setIdentityManager(identityManager);
var cacheManager = mock(CacheManager.class);
when(cacheManager.getConfig()).thenReturn(config);
when(cacheManager.getObject(eq(Device.class), anyLong())).thenReturn(device);
@@ -69,9 +63,6 @@ public class BaseTest {
when(cacheManager.getConfig()).thenReturn(mock(Config.class));
when(cacheManager.getObject(eq(Device.class), anyLong())).thenReturn(device);
encoder.setCacheManager(cacheManager);
- var identityManager = mock(IdentityManager.class);
- when(identityManager.getById(anyLong())).thenReturn(device);
- encoder.setIdentityManager(identityManager);
return encoder;
}
diff --git a/src/test/java/org/traccar/WebDataHandlerTest.java b/src/test/java/org/traccar/WebDataHandlerTest.java
index ff9c80ce6..1e6e1214f 100644
--- a/src/test/java/org/traccar/WebDataHandlerTest.java
+++ b/src/test/java/org/traccar/WebDataHandlerTest.java
@@ -3,13 +3,13 @@ package org.traccar;
import org.junit.Test;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.database.IdentityManager;
import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -28,10 +28,10 @@ public class WebDataHandlerTest extends ProtocolTest {
when(device.getName()).thenReturn("test");
when(device.getUniqueId()).thenReturn("123456789012345");
when(device.getStatus()).thenReturn(Device.STATUS_ONLINE);
- var identityManager = mock(IdentityManager.class);
- when(identityManager.getById(anyLong())).thenReturn(device);
+ var cacheManager = mock(CacheManager.class);
+ when(cacheManager.getObject(eq(Device.class), anyLong())).thenReturn(device);
- WebDataHandler handler = new WebDataHandler(config, mock(CacheManager.class), identityManager, null, null);
+ WebDataHandler handler = new WebDataHandler(config, cacheManager, null, null);
assertEquals(
"http://localhost/?fixTime=1451610123000&gprmc=$GPRMC,010203.000,A,2000.0000,N,03000.0000,E,0.00,0.00,010116,,*05&name=test",
diff --git a/src/test/java/org/traccar/handler/ComputedAttributesTest.java b/src/test/java/org/traccar/handler/ComputedAttributesTest.java
index e3886317c..2668c4f14 100644
--- a/src/test/java/org/traccar/handler/ComputedAttributesTest.java
+++ b/src/test/java/org/traccar/handler/ComputedAttributesTest.java
@@ -14,7 +14,7 @@ public class ComputedAttributesTest {
@Test
public void testComputedAttributes() {
- ComputedAttributesHandler handler = new ComputedAttributesHandler(new Config(), null, null);
+ ComputedAttributesHandler handler = new ComputedAttributesHandler(new Config(), null);
Date date = new Date();
Position position = new Position();
diff --git a/src/test/java/org/traccar/reports/ReportUtilsTest.java b/src/test/java/org/traccar/reports/ReportUtilsTest.java
index 1440c4c30..c7f2a2cc6 100644
--- a/src/test/java/org/traccar/reports/ReportUtilsTest.java
+++ b/src/test/java/org/traccar/reports/ReportUtilsTest.java
@@ -1,20 +1,21 @@
package org.traccar.reports;
import org.apache.velocity.app.VelocityEngine;
+import org.junit.Before;
import org.junit.Test;
import org.traccar.BaseTest;
import org.traccar.api.security.PermissionsService;
import org.traccar.config.Config;
import org.traccar.database.DeviceManager;
-import org.traccar.database.IdentityManager;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.reports.common.ReportUtils;
+import org.traccar.reports.common.TripsConfig;
import org.traccar.reports.model.StopReportItem;
import org.traccar.reports.model.TripReportItem;
-import org.traccar.reports.common.TripsConfig;
import org.traccar.storage.Storage;
+import org.traccar.storage.StorageException;
import java.text.DateFormat;
import java.text.ParseException;
@@ -30,11 +31,19 @@ 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.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ReportUtilsTest extends BaseTest {
+
+ private Storage storage;
+
+ @Before
+ public void init() throws StorageException {
+ storage = mock(Storage.class);
+ when(storage.getObject(any(), any())).thenReturn(mock(Device.class));
+ }
private Date date(String time) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
@@ -53,15 +62,7 @@ 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();
@@ -77,7 +78,7 @@ public class ReportUtilsTest extends BaseTest {
@Test
public void testCalculateSpentFuel() {
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), mock(TripsConfig.class), mock(VelocityEngine.class), null);
Position startPosition = new Position();
Position endPosition = new Position();
@@ -102,7 +103,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<TripReportItem> trips = reportUtils.detectTripsAndStops(data, false, TripReportItem.class);
@@ -157,7 +158,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, true, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<TripReportItem> trips = reportUtils.detectTripsAndStops(data, false, TripReportItem.class);
@@ -228,7 +229,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<TripReportItem> trips = reportUtils.detectTripsAndStops(data, false, TripReportItem.class);
@@ -279,7 +280,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<StopReportItem> result = reportUtils.detectTripsAndStops(data, false, StopReportItem.class);
@@ -308,7 +309,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<StopReportItem> result = reportUtils.detectTripsAndStops(data, false, StopReportItem.class);
@@ -337,7 +338,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<StopReportItem> result = reportUtils.detectTripsAndStops(data, false, StopReportItem.class);
@@ -366,7 +367,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<StopReportItem> result = reportUtils.detectTripsAndStops(data, false, StopReportItem.class);
@@ -391,7 +392,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, 900000, false, false, 0.01);
ReportUtils reportUtils = new ReportUtils(
- mock(Config.class), mock(Storage.class), mock(PermissionsService.class), mockIdentityManager(),
+ mock(Config.class), storage, mock(PermissionsService.class),
mock(DeviceManager.class), tripsConfig, mock(VelocityEngine.class), null);
Collection<TripReportItem> trips = reportUtils.detectTripsAndStops(data, false, TripReportItem.class);