aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/helper
diff options
context:
space:
mode:
authorChristoph Krey <c@ckrey.de>2018-04-16 10:45:11 +0200
committerGitHub <noreply@github.com>2018-04-16 10:45:11 +0200
commit3a602dd133b533cc69d5986d64a00fb3ed670f75 (patch)
tree97ff753db310a49ae7e53240b1db07fb8475679e /test/org/traccar/helper
parent232de5f0daef98f31b28d177d991fdbfa191f195 (diff)
parent6d4b8df25c7e942b9ad594db9444fe15bcb16be9 (diff)
downloadtraccar-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.gz
traccar-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.bz2
traccar-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.zip
Merge pull request #4 from traccar/master
upgrade to current master
Diffstat (limited to 'test/org/traccar/helper')
-rw-r--r--test/org/traccar/helper/BcdUtilTest.java7
-rw-r--r--test/org/traccar/helper/BitUtilTest.java27
-rw-r--r--test/org/traccar/helper/ChecksumTest.java30
-rw-r--r--test/org/traccar/helper/DateBuilderTest.java5
-rw-r--r--test/org/traccar/helper/DateUtilTest.java9
-rw-r--r--test/org/traccar/helper/DistanceCalculatorTest.java9
-rw-r--r--test/org/traccar/helper/LocationTreeTest.java11
-rw-r--r--test/org/traccar/helper/LogTest.java5
-rw-r--r--test/org/traccar/helper/ObdDecoderTest.java17
-rw-r--r--test/org/traccar/helper/PatternBuilderTest.java17
-rw-r--r--test/org/traccar/helper/StringFinderTest.java13
11 files changed, 82 insertions, 68 deletions
diff --git a/test/org/traccar/helper/BcdUtilTest.java b/test/org/traccar/helper/BcdUtilTest.java
index 8767ac890..e97aad09f 100644
--- a/test/org/traccar/helper/BcdUtilTest.java
+++ b/test/org/traccar/helper/BcdUtilTest.java
@@ -1,9 +1,10 @@
package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class BcdUtilTest {
@Test
@@ -11,7 +12,7 @@ public class BcdUtilTest {
byte[] buf = {0x01, (byte) 0x90, 0x34};
int result = BcdUtil.readInteger(
ChannelBuffers.wrappedBuffer(buf), 5);
- Assert.assertEquals(1903, result);
+ assertEquals(1903, result);
}
@Test
@@ -19,7 +20,7 @@ public class BcdUtilTest {
byte[] buf = {0x03, (byte) 0x85, 0x22, 0x59, 0x34};
double result = BcdUtil.readCoordinate(
ChannelBuffers.wrappedBuffer(buf));
- Assert.assertEquals(38.870989, result, 0.00001);
+ assertEquals(38.870989, result, 0.00001);
}
}
diff --git a/test/org/traccar/helper/BitUtilTest.java b/test/org/traccar/helper/BitUtilTest.java
index 4aa295e12..90431bf55 100644
--- a/test/org/traccar/helper/BitUtilTest.java
+++ b/test/org/traccar/helper/BitUtilTest.java
@@ -1,35 +1,38 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class BitUtilTest {
@Test
public void testCheck() {
- Assert.assertFalse(BitUtil.check(0, 0));
- Assert.assertTrue(BitUtil.check(1, 0));
- Assert.assertFalse(BitUtil.check(2, 0));
+ assertFalse(BitUtil.check(0, 0));
+ assertTrue(BitUtil.check(1, 0));
+ assertFalse(BitUtil.check(2, 0));
}
@Test
public void testBetween() {
- Assert.assertEquals(0, BitUtil.between(0, 0, 0));
- Assert.assertEquals(1, BitUtil.between(1, 0, 1));
- Assert.assertEquals(2, BitUtil.between(2, 0, 2));
- Assert.assertEquals(2, BitUtil.between(6, 0, 2));
+ assertEquals(0, BitUtil.between(0, 0, 0));
+ assertEquals(1, BitUtil.between(1, 0, 1));
+ assertEquals(2, BitUtil.between(2, 0, 2));
+ assertEquals(2, BitUtil.between(6, 0, 2));
}
@Test
public void testFrom() {
- Assert.assertEquals(1, BitUtil.from(1, 0));
- Assert.assertEquals(0, BitUtil.from(1, 1));
+ assertEquals(1, BitUtil.from(1, 0));
+ assertEquals(0, BitUtil.from(1, 1));
}
@Test
public void testTo() {
- Assert.assertEquals(2, BitUtil.to(2, 2));
- Assert.assertEquals(0, BitUtil.to(2, 1));
+ assertEquals(2, BitUtil.to(2, 2));
+ assertEquals(0, BitUtil.to(2, 1));
}
}
diff --git a/test/org/traccar/helper/ChecksumTest.java b/test/org/traccar/helper/ChecksumTest.java
index c37eda88d..3bd51448d 100644
--- a/test/org/traccar/helper/ChecksumTest.java
+++ b/test/org/traccar/helper/ChecksumTest.java
@@ -2,30 +2,38 @@ package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.junit.Assert;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
+import static org.junit.Assert.assertEquals;
+
public class ChecksumTest {
@Test
+ public void testCrc8() {
+ ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
+
+ assertEquals(0xF7, Checksum.crc8(Checksum.CRC8_EGTS, buf.toByteBuffer()));
+ assertEquals(0xD0, Checksum.crc8(Checksum.CRC8_ROHC, buf.toByteBuffer()));
+ }
+
+ @Test
public void testCrc16() {
ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
- Assert.assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
- Assert.assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
- Assert.assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
- Assert.assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer()));
- Assert.assertEquals(0xe5cc, Checksum.crc16(Checksum.CRC16_AUG_CCITT, buf.toByteBuffer()));
- Assert.assertEquals(0xd64e, Checksum.crc16(Checksum.CRC16_GENIBUS, buf.toByteBuffer()));
- Assert.assertEquals(0x6f91, Checksum.crc16(Checksum.CRC16_MCRF4XX, buf.toByteBuffer()));
+ assertEquals(0xBB3D, Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer()));
+ assertEquals(0x4B37, Checksum.crc16(Checksum.CRC16_MODBUS, buf.toByteBuffer()));
+ assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
+ assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
+ assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
+ assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer()));
}
-
+
@Test
public void testLuhn() {
- Assert.assertEquals(7, Checksum.luhn(12345678901234L));
- Assert.assertEquals(0, Checksum.luhn(63070019470771L));
+ assertEquals(7, Checksum.luhn(12345678901234L));
+ assertEquals(0, Checksum.luhn(63070019470771L));
}
}
diff --git a/test/org/traccar/helper/DateBuilderTest.java b/test/org/traccar/helper/DateBuilderTest.java
index 74936208b..b6323cc1d 100644
--- a/test/org/traccar/helper/DateBuilderTest.java
+++ b/test/org/traccar/helper/DateBuilderTest.java
@@ -1,6 +1,5 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.text.DateFormat;
@@ -8,6 +7,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
+import static org.junit.Assert.assertEquals;
+
public class DateBuilderTest {
@Test
@@ -19,7 +20,7 @@ public class DateBuilderTest {
DateBuilder dateBuilder = new DateBuilder()
.setDate(2015, 10, 20).setTime(1, 21, 11);
- Assert.assertEquals(dateFormat.parse("2015-10-20 01:21:11"), dateBuilder.getDate());
+ assertEquals(dateFormat.parse("2015-10-20 01:21:11"), dateBuilder.getDate());
}
diff --git a/test/org/traccar/helper/DateUtilTest.java b/test/org/traccar/helper/DateUtilTest.java
index ae5f20696..ec42e71ae 100644
--- a/test/org/traccar/helper/DateUtilTest.java
+++ b/test/org/traccar/helper/DateUtilTest.java
@@ -1,6 +1,5 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.text.DateFormat;
@@ -8,6 +7,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import static org.junit.Assert.assertEquals;
+
public class DateUtilTest {
@Test
@@ -15,13 +16,13 @@ public class DateUtilTest {
DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Assert.assertEquals(f.parse("2015-12-31 23:59:59"),
+ assertEquals(f.parse("2015-12-31 23:59:59"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 23:59:59"), Calendar.DAY_OF_MONTH));
- Assert.assertEquals(f.parse("2016-01-01 00:00:02"),
+ assertEquals(f.parse("2016-01-01 00:00:02"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 00:00:02"), Calendar.DAY_OF_MONTH));
- Assert.assertEquals(f.parse("2016-01-01 00:00:02"),
+ assertEquals(f.parse("2016-01-01 00:00:02"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2015-12-31 00:00:02"), Calendar.DAY_OF_MONTH));
}
diff --git a/test/org/traccar/helper/DistanceCalculatorTest.java b/test/org/traccar/helper/DistanceCalculatorTest.java
index 22e41c9a3..a7457b6c4 100644
--- a/test/org/traccar/helper/DistanceCalculatorTest.java
+++ b/test/org/traccar/helper/DistanceCalculatorTest.java
@@ -1,22 +1,23 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class DistanceCalculatorTest {
@Test
public void testDistance() {
- Assert.assertEquals(
+ assertEquals(
DistanceCalculator.distance(0.0, 0.0, 0.05, 0.05), 7863.0, 10.0);
}
@Test
public void testDistanceToLine() {
- Assert.assertEquals(DistanceCalculator.distanceToLine(
+ assertEquals(DistanceCalculator.distanceToLine(
56.83801, 60.59748, 56.83777, 60.59833, 56.83766, 60.5968), 33.0, 5.0);
- Assert.assertEquals(DistanceCalculator.distanceToLine(
+ assertEquals(DistanceCalculator.distanceToLine(
56.83753, 60.59508, 56.83777, 60.59833, 56.83766, 60.5968), 105.0, 5.0);
}
diff --git a/test/org/traccar/helper/LocationTreeTest.java b/test/org/traccar/helper/LocationTreeTest.java
index afbbbc94c..21604144a 100644
--- a/test/org/traccar/helper/LocationTreeTest.java
+++ b/test/org/traccar/helper/LocationTreeTest.java
@@ -1,11 +1,12 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+
public class LocationTreeTest {
@Test
@@ -19,10 +20,10 @@ public class LocationTreeTest {
LocationTree tree = new LocationTree(items);
- Assert.assertEquals("a", tree.findNearest(new LocationTree.Item(1f, 1f)).getData());
- Assert.assertEquals("d", tree.findNearest(new LocationTree.Item(10f, 10f)).getData());
- Assert.assertEquals("c", tree.findNearest(new LocationTree.Item(1f, 2.5f)).getData());
- Assert.assertEquals("a", tree.findNearest(new LocationTree.Item(1.5f, 1.5f)).getData());
+ assertEquals("a", tree.findNearest(new LocationTree.Item(1f, 1f)).getData());
+ assertEquals("d", tree.findNearest(new LocationTree.Item(10f, 10f)).getData());
+ assertEquals("c", tree.findNearest(new LocationTree.Item(1f, 2.5f)).getData());
+ assertEquals("a", tree.findNearest(new LocationTree.Item(1.5f, 1.5f)).getData());
}
diff --git a/test/org/traccar/helper/LogTest.java b/test/org/traccar/helper/LogTest.java
index 579c13e7d..853eb05c9 100644
--- a/test/org/traccar/helper/LogTest.java
+++ b/test/org/traccar/helper/LogTest.java
@@ -1,13 +1,14 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class LogTest {
@Test
public void testLog() {
- Assert.assertEquals("test - Exception (LogTest:10 < ...)", Log.exceptionStack(new Exception("test")));
+ assertEquals("test - Exception (LogTest:11 < ...)", Log.exceptionStack(new Exception("test")));
}
}
diff --git a/test/org/traccar/helper/ObdDecoderTest.java b/test/org/traccar/helper/ObdDecoderTest.java
index db84d46d7..1ffe68c8b 100644
--- a/test/org/traccar/helper/ObdDecoderTest.java
+++ b/test/org/traccar/helper/ObdDecoderTest.java
@@ -1,25 +1,26 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class ObdDecoderTest {
@Test
public void testDecode() {
- Assert.assertEquals(83, ObdDecoder.decode(0x01, "057b").getValue());
- Assert.assertEquals(1225, ObdDecoder.decode(0x01, "0C1324").getValue());
- Assert.assertEquals(20, ObdDecoder.decode(0x01, "0D14").getValue());
- Assert.assertEquals(64050, ObdDecoder.decode(0x01, "31fa32").getValue());
- Assert.assertEquals(25, ObdDecoder.decode(0x01, "2F41").getValue());
+ assertEquals(83, ObdDecoder.decode(0x01, "057b").getValue());
+ assertEquals(1225, ObdDecoder.decode(0x01, "0C1324").getValue());
+ assertEquals(20, ObdDecoder.decode(0x01, "0D14").getValue());
+ assertEquals(64050, ObdDecoder.decode(0x01, "31fa32").getValue());
+ assertEquals(25, ObdDecoder.decode(0x01, "2F41").getValue());
}
@Test
public void testDecodeCodes() throws Exception {
- Assert.assertEquals("P0D14", ObdDecoder.decodeCodes("0D14").getValue());
- Assert.assertEquals("dtcs", ObdDecoder.decodeCodes("0D14").getKey());
+ assertEquals("P0D14", ObdDecoder.decodeCodes("0D14").getValue());
+ assertEquals("dtcs", ObdDecoder.decodeCodes("0D14").getKey());
}
}
diff --git a/test/org/traccar/helper/PatternBuilderTest.java b/test/org/traccar/helper/PatternBuilderTest.java
index 975cc1621..4c76bc463 100644
--- a/test/org/traccar/helper/PatternBuilderTest.java
+++ b/test/org/traccar/helper/PatternBuilderTest.java
@@ -1,19 +1,20 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class PatternBuilderTest {
@Test
public void testPatternBuilder() {
- Assert.assertEquals("\\$GPRMC", new PatternBuilder().text("$GPRMC").toString());
- Assert.assertEquals("(\\d{2}\\.[0-9a-fA-F]+)", new PatternBuilder().number("(dd.x+)").toString());
- Assert.assertEquals("a(?:bc)?", new PatternBuilder().text("a").text("b").text("c").optional(2).toString());
- Assert.assertEquals("a|b", new PatternBuilder().expression("a|b").toString());
- Assert.assertEquals("ab\\|", new PatternBuilder().expression("ab|").toString());
- Assert.assertEquals("|", new PatternBuilder().or().toString());
- Assert.assertEquals("\\|\\d|\\d\\|", new PatternBuilder().number("|d|d|").toString());
+ assertEquals("\\$GPRMC", new PatternBuilder().text("$GPRMC").toString());
+ assertEquals("(\\d{2}\\.[0-9a-fA-F]+)", new PatternBuilder().number("(dd.x+)").toString());
+ assertEquals("a(?:bc)?", new PatternBuilder().text("a").text("b").text("c").optional(2).toString());
+ assertEquals("a|b", new PatternBuilder().expression("a|b").toString());
+ assertEquals("ab\\|", new PatternBuilder().expression("ab|").toString());
+ assertEquals("|", new PatternBuilder().or().toString());
+ assertEquals("\\|\\d|\\d\\|", new PatternBuilder().number("|d|d|").toString());
}
}
diff --git a/test/org/traccar/helper/StringFinderTest.java b/test/org/traccar/helper/StringFinderTest.java
index 1c8234db1..f35f9a759 100644
--- a/test/org/traccar/helper/StringFinderTest.java
+++ b/test/org/traccar/helper/StringFinderTest.java
@@ -1,16 +1,11 @@
package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.buffer.HeapChannelBufferFactory;
-import org.junit.Assert;
import org.junit.Test;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class StringFinderTest {
@@ -20,10 +15,10 @@ public class StringFinderTest {
ChannelBuffer buf = ChannelBuffers.copiedBuffer("hello world", StandardCharsets.US_ASCII);
- Assert.assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
- Assert.assertEquals(6, buf.indexOf(0, buf.writerIndex(), new StringFinder("world")));
- Assert.assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("worlds")));
- Assert.assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));
+ assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
+ assertEquals(6, buf.indexOf(0, buf.writerIndex(), new StringFinder("world")));
+ assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("worlds")));
+ assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));
}