aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/org/traccar/protocol/Tk103ProtocolEncoderTest.java')
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolEncoderTest.java96
1 files changed, 66 insertions, 30 deletions
diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
index 2e5b66572..4afb7b0e4 100644
--- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
@@ -11,11 +11,6 @@ import org.traccar.model.Position;
public class Tk103ProtocolEncoderTest extends ProtocolTest {
- private static IdentityManager defaultManager;
- static {
- defaultManager = Context.getIdentityManager();
- }
-
private static IdentityManager t580wManager = new IdentityManager() {
private Device createDevice() {
@@ -81,8 +76,6 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AV011)", encoder.encodeCommand(command));
}
@@ -96,13 +89,16 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_SINGLE);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -116,13 +112,16 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_POSITION_PERIODIC);
command.set(Command.KEY_FREQUENCY, 60);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -135,13 +134,16 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_STOP);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -154,13 +156,16 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_GET_VERSION);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -173,13 +178,16 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -192,8 +200,6 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_SET_ODOMETER);
- Context.init(defaultManager);
-
Assert.assertEquals("(123456789012345AX01)", encoder.encodeCommand(command));
}
@@ -207,9 +213,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_IDENTIFICATION);
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -223,9 +234,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, true);
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -239,9 +255,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, false);
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -255,9 +276,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "any text is ok");
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -272,9 +298,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_SERVER, "1.2.3.4");
command.set(Command.KEY_PORT, "5555");
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}
@@ -289,9 +320,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_INDEX, "0");
command.set(Command.KEY_PHONE, "+55555555555");
+ IdentityManager old = Context.getIdentityManager();
Context.init(t580wManager);
- Assert.assertEquals("[begin]sms2,*master*654321*+55555555555*,[end]", encoder.encodeCommand(command));
+ try {
+ Assert.assertEquals("[begin]sms2,*master*654321*+55555555555*,[end]", encoder.encodeCommand(command));
+ } finally {
+ Context.init(old);
+ }
}