aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/ProtocolTest.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-01-25 20:14:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-01-26 08:41:45 +1300
commit87bdccbe9843e38174ad345b8e474b1cded9f985 (patch)
tree4b2f90ad2b9a5d32410ab9579fb4135b5ac95bfa /test/org/traccar/ProtocolTest.java
parent8535983fea8c09046c53f2ebf388bbf3fae594ce (diff)
downloadtrackermap-server-87bdccbe9843e38174ad345b8e474b1cded9f985.tar.gz
trackermap-server-87bdccbe9843e38174ad345b8e474b1cded9f985.tar.bz2
trackermap-server-87bdccbe9843e38174ad345b8e474b1cded9f985.zip
Static imports for junit
Diffstat (limited to 'test/org/traccar/ProtocolTest.java')
-rw-r--r--test/org/traccar/ProtocolTest.java118
1 files changed, 61 insertions, 57 deletions
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 5cbb651bf..246e3d0e7 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -21,6 +21,12 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
public class ProtocolTest extends BaseTest {
protected Position position(String time, boolean valid, double lat, double lon) throws ParseException {
@@ -77,19 +83,19 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyNotNull(BaseProtocolDecoder decoder, Object object) throws Exception {
- Assert.assertNotNull(decoder.decode(null, null, object));
+ assertNotNull(decoder.decode(null, null, object));
}
protected void verifyNull(Object object) throws Exception {
- Assert.assertNull(object);
+ assertNull(object);
}
protected void verifyNull(BaseProtocolDecoder decoder, Object object) throws Exception {
- Assert.assertNull(decoder.decode(null, null, object));
+ assertNull(decoder.decode(null, null, object));
}
protected void verifyAttribute(BaseProtocolDecoder decoder, Object object, String key, Object expected) throws Exception {
- Assert.assertEquals(expected, ((Position) decoder.decode(null, null, object)).getAttributes().get(key));
+ assertEquals(expected, ((Position) decoder.decode(null, null, object)).getAttributes().get(key));
}
protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception {
@@ -118,9 +124,9 @@ public class ProtocolTest extends BaseTest {
private void verifyDecodedList(Object decodedObject, boolean checkLocation, Position expected) {
- Assert.assertNotNull("list is null", decodedObject);
- Assert.assertTrue("not a list", decodedObject instanceof List);
- Assert.assertFalse("list is empty", ((List) decodedObject).isEmpty());
+ assertNotNull("list is null", decodedObject);
+ assertTrue("not a list", decodedObject instanceof List);
+ assertFalse("list is empty", ((List) decodedObject).isEmpty());
for (Object item : (List) decodedObject) {
verifyDecodedPosition(item, checkLocation, false, expected);
@@ -130,8 +136,8 @@ public class ProtocolTest extends BaseTest {
private void verifyDecodedPosition(Object decodedObject, boolean checkLocation, boolean checkAttributes, Position expected) {
- Assert.assertNotNull("position is null", decodedObject);
- Assert.assertTrue("not a position", decodedObject instanceof Position);
+ assertNotNull("position is null", decodedObject);
+ assertTrue("not a position", decodedObject instanceof Position);
Position position = (Position) decodedObject;
@@ -142,125 +148,125 @@ public class ProtocolTest extends BaseTest {
if (expected.getFixTime() != null) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- Assert.assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
+ assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
}
- Assert.assertEquals("valid", expected.getValid(), position.getValid());
- Assert.assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
- Assert.assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
+ assertEquals("valid", expected.getValid(), position.getValid());
+ assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
+ assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
} else {
- Assert.assertNotNull(position.getFixTime());
- Assert.assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
- Assert.assertTrue("time < +25 hours",
+ assertNotNull(position.getFixTime());
+ assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
+ assertTrue("time < +25 hours",
position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000);
- Assert.assertTrue("latitude >= -90", position.getLatitude() >= -90);
- Assert.assertTrue("latitude <= 90", position.getLatitude() <= 90);
+ assertTrue("latitude >= -90", position.getLatitude() >= -90);
+ assertTrue("latitude <= 90", position.getLatitude() <= 90);
- Assert.assertTrue("longitude >= -180", position.getLongitude() >= -180);
- Assert.assertTrue("longitude <= 180", position.getLongitude() <= 180);
+ assertTrue("longitude >= -180", position.getLongitude() >= -180);
+ assertTrue("longitude <= 180", position.getLongitude() <= 180);
}
- Assert.assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
- Assert.assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
+ assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
+ assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
- Assert.assertTrue("speed >= 0", position.getSpeed() >= 0);
- Assert.assertTrue("speed <= 869", position.getSpeed() <= 869);
+ assertTrue("speed >= 0", position.getSpeed() >= 0);
+ assertTrue("speed <= 869", position.getSpeed() <= 869);
- Assert.assertTrue("course >= 0", position.getCourse() >= 0);
- Assert.assertTrue("course <= 360", position.getCourse() <= 360);
+ assertTrue("course >= 0", position.getCourse() >= 0);
+ assertTrue("course <= 360", position.getCourse() <= 360);
- Assert.assertNotNull("protocol is null", position.getProtocol());
+ assertNotNull("protocol is null", position.getProtocol());
}
Map<String, Object> attributes = position.getAttributes();
if (checkAttributes) {
- Assert.assertFalse("no attributes", attributes.isEmpty());
+ assertFalse("no attributes", attributes.isEmpty());
}
if (attributes.containsKey(Position.KEY_INDEX)) {
- Assert.assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
}
if (attributes.containsKey(Position.KEY_HDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_VDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_PDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES)) {
- Assert.assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES_VISIBLE)) {
- Assert.assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RSSI)) {
- Assert.assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ODOMETER)) {
- Assert.assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RPM)) {
- Assert.assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
}
if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) {
- Assert.assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
}
if (attributes.containsKey(Position.KEY_POWER)) {
- Assert.assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY)) {
- Assert.assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY_LEVEL)) {
int batteryLevel = ((Number) attributes.get(Position.KEY_BATTERY_LEVEL)).intValue();
- Assert.assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
+ assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
}
if (attributes.containsKey(Position.KEY_CHARGE)) {
- Assert.assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_IGNITION)) {
- Assert.assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_MOTION)) {
- Assert.assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_ARCHIVE)) {
- Assert.assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
- Assert.assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
+ assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
}
if (attributes.containsKey(Position.KEY_STEPS)) {
- Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ROAMING)) {
- Assert.assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
}
if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) {
@@ -275,11 +281,11 @@ public class ProtocolTest extends BaseTest {
}
private void checkInteger(Object value, int min, int max) {
- Assert.assertNotNull("value is null", value);
- Assert.assertTrue("not int or long", value instanceof Integer || value instanceof Long);
+ assertNotNull("value is null", value);
+ assertTrue("not int or long", value instanceof Integer || value instanceof Long);
long number = ((Number) value).longValue();
- Assert.assertTrue("value too low", number >= min);
- Assert.assertTrue("value too high", number <= max);
+ assertTrue("value too low", number >= min);
+ assertTrue("value too high", number <= max);
}
protected void verifyCommand(
@@ -288,11 +294,9 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyFrame(ChannelBuffer expected, Object object) {
-
- Assert.assertNotNull("buffer is null", object);
- Assert.assertTrue("not a buffer", object instanceof ChannelBuffer);
- Assert.assertEquals(ChannelBuffers.hexDump(expected), ChannelBuffers.hexDump((ChannelBuffer) object));
-
+ assertNotNull("buffer is null", object);
+ assertTrue("not a buffer", object instanceof ChannelBuffer);
+ assertEquals(ChannelBuffers.hexDump(expected), ChannelBuffers.hexDump((ChannelBuffer) object));
}
}