diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-23 09:40:20 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-23 09:40:20 +1300 |
commit | b4d3a5de05422b88e518a173359d45ce13ea4b2b (patch) | |
tree | 827b7545b17645f1fa0598fbf19bef52ca9383eb /test/org | |
parent | c585535761dba635dca000f900cc33d4cc5e4631 (diff) | |
download | trackermap-server-b4d3a5de05422b88e518a173359d45ce13ea4b2b.tar.gz trackermap-server-b4d3a5de05422b88e518a173359d45ce13ea4b2b.tar.bz2 trackermap-server-b4d3a5de05422b88e518a173359d45ce13ea4b2b.zip |
Fix date builder and unit testing
Diffstat (limited to 'test/org')
-rw-r--r-- | test/org/traccar/ProtocolDecoderTest.java | 8 | ||||
-rw-r--r-- | test/org/traccar/helper/DateBuilderTest.java | 26 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 31 |
3 files changed, 44 insertions, 21 deletions
diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index f58de880a..03e8314d6 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -79,7 +79,8 @@ public class ProtocolDecoderTest { Position position = new Position(); if (time != null) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); position.setTime(dateFormat.parse(time)); } position.setValid(valid); @@ -136,10 +137,7 @@ public class ProtocolDecoderTest { Position position = (Position) decodedObject; if (expected.getFixTime() != null) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - Assert.assertEquals("time", - dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime())); + Assert.assertEquals("time", expected.getFixTime(), position.getFixTime()); } Assert.assertEquals("valid", expected.getValid(), position.getValid()); Assert.assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001); diff --git a/test/org/traccar/helper/DateBuilderTest.java b/test/org/traccar/helper/DateBuilderTest.java new file mode 100644 index 000000000..8e474e059 --- /dev/null +++ b/test/org/traccar/helper/DateBuilderTest.java @@ -0,0 +1,26 @@ +package org.traccar.helper; + +import org.junit.Assert; +import org.junit.Test; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.TimeZone; + +public class DateBuilderTest { + + @Test + public void testDateBuilder() throws ParseException { + + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(2015, 10, 20).setTime(01, 21, 11); + + Assert.assertEquals(dateFormat.parse("2015-10-20 01:21:11"), dateBuilder.getDate()); + + } + +} diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 8825b67f0..0de82db32 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -11,14 +11,20 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(new Gt06Protocol()); verifyNothing(decoder, binary( - "787811010123456789012345100B3201000171930D0A")); + "78780D01086471700328358100093F040D0A")); + + verifyNothing(decoder, binary( + "78780D01012345678901234500018CDD0D0A")); + + verifyNothing(decoder, binary( + "78780d0103534190360660610003c3df0d0a")); verifyAttributes(decoder, binary( "78780a13440604000201baaf540d0a")); verifyPosition(decoder, binary( - "78781f120f0a140e150bc505e51e780293a9e800540000f601006e0055da00035f240d0a")/*, - position("2015-10-20 14:21:11", true, 54.94535, 24.01762)*/); + "78781f120f0a140e150bc505e51e780293a9e800540000f601006e0055da00035f240d0a"), + position("2015-10-20 14:21:11.000", true, 54.94535, 24.01762)); verifyPosition(decoder, binary( "787823120f081b121d37cb01c8e2cc08afd3c020d50201940701d600a1190041ee100576d1470d0a")); @@ -26,15 +32,6 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { verifyPosition(decoder, binary( "78781F120B081D112E10CC027AC7EB0C46584900148F01CC00287D001FB8000380810D0A")); - verifyNothing(decoder, binary( - "78780D01086471700328358100093F040D0A")); - - verifyNothing(decoder, binary( - "78780D01012345678901234500018CDD0D0A")); - - verifyNothing(decoder, binary( - "78780d0103534190360660610003c3df0d0a")); - verifyPosition(decoder, binary( "787819100B031A0B1B31CC027AC7FD0C4657BF0115210001001CC6070D0A")); @@ -43,10 +40,6 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { verifyPosition(decoder, binary( "787825160B051B093523CF027AC8360C4657B30014000901CC00266A001E1740050400020008D7B10D0A")); - // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 - - verifyNothing(decoder, binary( - "787811010864717003664467100f190a0002c6d20d0a")); verifyPosition(decoder, binary( "787819100e010903230ec803ae32a60653cded00180000020072feb70d0a")); @@ -63,6 +56,12 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { verifyPosition(decoder, binary( "787822220e0914160f07c9021a362805090a7800d8b802d402c30e00a98a0105010213f4bb0d0a")); + verifyNothing(decoder, binary( + "787811010864717003664467100f190a0002c6d20d0a")); + + verifyNothing(decoder, binary( + "787811010123456789012345100B3201000171930D0A")); + } } |