aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/BaseTest.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 14:48:42 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 14:48:42 -0700
commit0202dbf7258df8cbe8168ddc985e774b1cadf964 (patch)
tree4828e614e29715e6bdfd10c5db86b52e43229ab3 /src/test/java/org/traccar/BaseTest.java
parent014cf82a9e63a36e944e293932f9edf27e452919 (diff)
downloadtrackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.tar.gz
trackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.tar.bz2
trackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.zip
Decouple more tests from context
Diffstat (limited to 'src/test/java/org/traccar/BaseTest.java')
-rw-r--r--src/test/java/org/traccar/BaseTest.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/java/org/traccar/BaseTest.java b/src/test/java/org/traccar/BaseTest.java
index 35374a363..2eedd4bd8 100644
--- a/src/test/java/org/traccar/BaseTest.java
+++ b/src/test/java/org/traccar/BaseTest.java
@@ -1,5 +1,7 @@
package org.traccar;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import org.traccar.config.Config;
import org.traccar.database.ConnectionManager;
import org.traccar.database.IdentityManager;
@@ -7,7 +9,12 @@ import org.traccar.database.MediaManager;
import org.traccar.database.StatisticsManager;
import org.traccar.model.Device;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class BaseTest {
@@ -20,7 +27,14 @@ public class BaseTest {
var device = mock(Device.class);
when(device.getId()).thenReturn(1L);
var identityManager = mock(IdentityManager.class);
+ when(identityManager.getById(anyLong())).thenReturn(device);
when(identityManager.getByUniqueId(any())).thenReturn(device);
+ when(identityManager.lookupAttributeBoolean(anyLong(), any(), anyBoolean(), anyBoolean(), anyBoolean()))
+ .thenAnswer(invocation -> invocation.getArguments()[2]);
+ when(identityManager.lookupAttributeString(anyLong(), any(), any(), anyBoolean(), anyBoolean()))
+ .thenAnswer(invocation -> invocation.getArguments()[2]);
+ when(identityManager.lookupAttributeInteger(anyLong(), any(), anyInt(), anyBoolean(), anyBoolean()))
+ .thenAnswer(invocation -> invocation.getArguments()[2]);
decoder.setIdentityManager(identityManager);
decoder.setConnectionManager(mock(ConnectionManager.class));
decoder.setStatisticsManager(mock(StatisticsManager.class));
@@ -33,6 +47,15 @@ public class BaseTest {
}
protected <T extends BaseProtocolEncoder> T inject(T encoder) throws Exception {
+ var device = mock(Device.class);
+ when(device.getId()).thenReturn(1L);
+ when(device.getUniqueId()).thenReturn("123456789012345");
+ var identityManager = mock(IdentityManager.class);
+ when(identityManager.getDevicePassword(anyLong(), any(), any()))
+ .thenAnswer(invocation -> invocation.getArguments()[2]);
+ when(identityManager.getById(anyLong())).thenReturn(device);
+ when(identityManager.getByUniqueId(any())).thenReturn(device);
+ encoder.setIdentityManager(identityManager);
return encoder;
}