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.java27
-rw-r--r--src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java18
2 files changed, 10 insertions, 35 deletions
diff --git a/src/test/java/org/traccar/BaseTest.java b/src/test/java/org/traccar/BaseTest.java
index 0b2c616ce..1dddbb03b 100644
--- a/src/test/java/org/traccar/BaseTest.java
+++ b/src/test/java/org/traccar/BaseTest.java
@@ -1,34 +1,9 @@
package org.traccar;
-import io.netty.buffer.ByteBuf;
-import org.traccar.database.MediaManager;
-
-import java.util.HashMap;
-import java.util.Map;
-
public class BaseTest {
- public static class MockMediaManager extends MediaManager {
- Map<String, ByteBuf> files = new HashMap<>();
-
- MockMediaManager() {
- super("");
- }
-
- @Override
- public String writeFile(String uniqueId, ByteBuf buf, String extension) {
- String fileName = uniqueId + "/mock." + extension;
- files.put(fileName, buf);
- return fileName;
- }
-
- public ByteBuf readFile(String fileName) {
- return files.get(fileName);
- }
- }
-
static {
- Context.init(new TestIdentityManager(), new MockMediaManager());
+ Context.init(new TestIdentityManager());
}
}
diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
index ef6c33da9..50baaa81a 100644
--- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -1,12 +1,11 @@
package org.traccar.protocol;
-import io.netty.buffer.ByteBuf;
import org.junit.Test;
-import org.traccar.Context;
import org.traccar.ProtocolTest;
+import org.traccar.database.MediaManager;
import org.traccar.model.Position;
-import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
public class WatchProtocolDecoderTest extends ProtocolTest {
@@ -148,14 +147,15 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
var decoder = new WatchProtocolDecoder(null);
- verifyNull(decoder.decode(null, null, buffer("[CS*1234567890*0004*TK,1]")));
+ var mediaManager = mock(MediaManager.class);
+ when(mediaManager.writeFile(any(), any(), any())).thenReturn("mock.amr");
+ decoder.setMediaManager(mediaManager);
- ByteBuf data = binary("7d5b5d2c2aff");
+ verifyAttribute(decoder, concatenateBuffers(
+ buffer("[CS*1234567890*000e*TK,#!AMR"), binary("7d5b5d2c2aff"), buffer("]")),
+ Position.KEY_AUDIO, "mock.amr");
- Object decodedObject = decoder.decode(null, null, concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), data.resetReaderIndex(), buffer("]")));
- assertEquals("1234567890/mock.amr", ((Position) decodedObject).getAttributes().get("audio"));
-
- verifyFrame(concatenateBuffers(buffer("#!AMR"), data.resetReaderIndex()), ((MockMediaManager) Context.getMediaManager()).readFile("1234567890/mock.amr"));
+ verify(mediaManager).writeFile(any(), any(), any());
}