diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-15 13:44:42 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-15 13:44:42 +1300 |
commit | f9f37325f1161ddc2b726171e8af0dbb25787c6e (patch) | |
tree | f31fefc3f41ab75dc2ce77aa3d851c6ced060fc6 /test/org | |
parent | 193d8f8feaf621e3c20f5b93133fae80dc2e6d8f (diff) | |
download | traccar-server-f9f37325f1161ddc2b726171e8af0dbb25787c6e.tar.gz traccar-server-f9f37325f1161ddc2b726171e8af0dbb25787c6e.tar.bz2 traccar-server-f9f37325f1161ddc2b726171e8af0dbb25787c6e.zip |
Clean up unit testing util class
Diffstat (limited to 'test/org')
-rw-r--r-- | test/org/traccar/ProtocolDecoderTest.java | 135 |
1 files changed, 62 insertions, 73 deletions
diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 133b0229f..a142f2d4d 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -45,46 +45,6 @@ public class ProtocolDecoderTest { }); } - protected void verifyNothing(BaseProtocolDecoder decoder, Object object) throws Exception { - Assert.assertNull(decoder.decode(null, null, object)); - } - - protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception { - Object decodedObject = decoder.decode(null, null, object); - Assert.assertNotNull("position is null", decodedObject); - Assert.assertTrue("not a position", decodedObject instanceof Position); - Position position = (Position) decodedObject; - Assert.assertFalse("no attributes", position.getAttributes().isEmpty()); - } - - protected void verifyPosition(BaseProtocolDecoder decoder, Object object) throws Exception { - verifyDecodedPosition(decoder.decode(null, null, object)); - } - - protected void verifyPosition(BaseProtocolDecoder decoder, Object object, Position position) throws Exception { - verifyDecodedPosition(decoder.decode(null, null, object), position); - } - - protected void verifyPositions(BaseProtocolDecoder decoder, Object object) throws Exception { - Object decodedObject = decoder.decode(null, null, object); - Assert.assertNotNull("list is null", decodedObject); - Assert.assertTrue("not a list", decodedObject instanceof List); - Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); - for (Object item : (List) decodedObject) { - verifyDecodedPosition(item); - } - } - - protected void verifyPositions(BaseProtocolDecoder decoder, Object object, Position position) throws Exception { - Object decodedObject = decoder.decode(null, null, object); - Assert.assertNotNull("list is null", decodedObject); - Assert.assertTrue("not a list", decodedObject instanceof List); - Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); - for (Object item : (List) decodedObject) { - verifyDecodedPosition(item, position); - } - } - protected Position position(String time, boolean valid, double lat, double lon) throws ParseException { Position position = new Position(); @@ -140,61 +100,90 @@ public class ProtocolDecoderTest { return request; } - private void verifyDecodedPosition(Object decodedObject, Position expected) { + protected void verifyNothing(BaseProtocolDecoder decoder, Object object) throws Exception { + Assert.assertNull(decoder.decode(null, null, object)); + } + + protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception { + verifyDecodedPosition(decoder.decode(null, null, object), false, true, null); + } - Assert.assertNotNull("position is null", decodedObject); - Assert.assertTrue("not a position", decodedObject instanceof Position); + protected void verifyPosition(BaseProtocolDecoder decoder, Object object) throws Exception { + verifyDecodedPosition(decoder.decode(null, null, object), true, false, null); + } - Position position = (Position) decodedObject; + protected void verifyPosition(BaseProtocolDecoder decoder, Object object, Position position) throws Exception { + verifyDecodedPosition(decoder.decode(null, null, object), true, false, position); + } - if (expected.getFixTime() != null) { - Assert.assertEquals("time", expected.getFixTime(), 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); + protected void verifyPositions(BaseProtocolDecoder decoder, Object object) throws Exception { + verifyDecodedList(decoder.decode(null, null, object), null); + } - Assert.assertTrue("altitude >= -12262", position.getAltitude() >= -12262); - Assert.assertTrue("altitude <= 18000", position.getAltitude() <= 18000); + protected void verifyPositions(BaseProtocolDecoder decoder, Object object, Position position) throws Exception { + verifyDecodedList(decoder.decode(null, null, object), position); + } - Assert.assertTrue("speed >= 0", position.getSpeed() >= 0); - Assert.assertTrue("speed <= 869", position.getSpeed() <= 869); + private void verifyDecodedList(Object decodedObject, Position expected) { - Assert.assertTrue("course >= 0", position.getCourse() >= 0); - Assert.assertTrue("course <= 360", position.getCourse() <= 360); + Assert.assertNotNull("list is null", decodedObject); + Assert.assertTrue("not a list", decodedObject instanceof List); + Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); - Assert.assertNotNull("protocol is null", position.getProtocol()); + for (Object item : (List) decodedObject) { + verifyDecodedPosition(item, true, false, expected); + } } - private void verifyDecodedPosition(Object decodedObject) { + 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); Position position = (Position) decodedObject; - Assert.assertNotNull(position.getFixTime()); - Assert.assertTrue("year > 2000", position.getFixTime().after(new Date(946684800000L))); - Assert.assertTrue("time < +25 hours", - position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000); + if (checkLocation) { + + if (expected != null) { + + if (expected.getFixTime() != null) { + Assert.assertEquals("time", expected.getFixTime(), 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); + + } else { - Assert.assertTrue("latitude >= -90", position.getLatitude() >= -90); - Assert.assertTrue("latitude <= 90", position.getLatitude() <= 90); + Assert.assertNotNull(position.getFixTime()); + Assert.assertTrue("year > 2000", position.getFixTime().after(new Date(946684800000L))); + Assert.assertTrue("time < +25 hours", + position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000); - Assert.assertTrue("longitude >= -180", position.getLongitude() >= -180); - Assert.assertTrue("longitude <= 180", position.getLongitude() <= 180); + Assert.assertTrue("latitude >= -90", position.getLatitude() >= -90); + Assert.assertTrue("latitude <= 90", position.getLatitude() <= 90); - Assert.assertTrue("altitude >= -12262", position.getAltitude() >= -12262); - Assert.assertTrue("altitude <= 18000", position.getAltitude() <= 18000); + } + + Assert.assertTrue("altitude >= -12262", position.getAltitude() >= -12262); + Assert.assertTrue("altitude <= 18000", position.getAltitude() <= 18000); + + Assert.assertTrue("speed >= 0", position.getSpeed() >= 0); + Assert.assertTrue("speed <= 869", position.getSpeed() <= 869); + + Assert.assertTrue("course >= 0", position.getCourse() >= 0); + Assert.assertTrue("course <= 360", position.getCourse() <= 360); - Assert.assertTrue("speed >= 0", position.getSpeed() >= 0); - Assert.assertTrue("speed <= 869", position.getSpeed() <= 869); + Assert.assertNotNull("protocol is null", position.getProtocol()); - Assert.assertTrue("course >= 0", position.getCourse() >= 0); - Assert.assertTrue("course <= 360", position.getCourse() <= 360); + } + + if (checkAttributes) { - Assert.assertNotNull("protocol is null", position.getProtocol()); + Assert.assertFalse("no attributes", position.getAttributes().isEmpty()); + + } } |