aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/helper
diff options
context:
space:
mode:
authorYuriy Piskarev <yuriy.piskarev@gmail.com>2023-08-24 14:16:17 +0300
committerGitHub <noreply@github.com>2023-08-24 14:16:17 +0300
commitae406c7b49a72de24d81fd74386d9638342c90ee (patch)
tree6fbcf557375b98e926c78af9c757e62c79d72a1b /src/test/java/org/traccar/helper
parent56ff656c908b19feb2fa3dcffa48cc3bcdfe9b3b (diff)
parent9aeedc90da24848ff97227d6f281eb4d1e1506ef (diff)
downloadtrackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.gz
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.bz2
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.zip
Merge branch 'traccar:master' into master
Diffstat (limited to 'src/test/java/org/traccar/helper')
-rw-r--r--src/test/java/org/traccar/helper/BcdUtilTest.java4
-rw-r--r--src/test/java/org/traccar/helper/BitBufferTest.java4
-rw-r--r--src/test/java/org/traccar/helper/BitUtilTest.java8
-rw-r--r--src/test/java/org/traccar/helper/BufferUtilTest.java10
-rw-r--r--src/test/java/org/traccar/helper/ChecksumTest.java4
-rw-r--r--src/test/java/org/traccar/helper/DateBuilderTest.java4
-rw-r--r--src/test/java/org/traccar/helper/DateUtilTest.java4
-rw-r--r--src/test/java/org/traccar/helper/DistanceCalculatorTest.java4
-rw-r--r--src/test/java/org/traccar/helper/LogTest.java4
-rw-r--r--src/test/java/org/traccar/helper/ObdDecoderTest.java4
-rw-r--r--src/test/java/org/traccar/helper/PatternBuilderTest.java4
-rw-r--r--src/test/java/org/traccar/helper/PatternUtilTest.java8
-rw-r--r--src/test/java/org/traccar/helper/ServletHelperTest.java65
-rw-r--r--src/test/java/org/traccar/helper/WebHelperTest.java39
14 files changed, 73 insertions, 93 deletions
diff --git a/src/test/java/org/traccar/helper/BcdUtilTest.java b/src/test/java/org/traccar/helper/BcdUtilTest.java
index 86a32f725..440cd90d4 100644
--- a/src/test/java/org/traccar/helper/BcdUtilTest.java
+++ b/src/test/java/org/traccar/helper/BcdUtilTest.java
@@ -1,9 +1,9 @@
package org.traccar.helper;
import io.netty.buffer.Unpooled;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class BcdUtilTest {
diff --git a/src/test/java/org/traccar/helper/BitBufferTest.java b/src/test/java/org/traccar/helper/BitBufferTest.java
index c2abad36d..3b3521213 100644
--- a/src/test/java/org/traccar/helper/BitBufferTest.java
+++ b/src/test/java/org/traccar/helper/BitBufferTest.java
@@ -1,8 +1,8 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class BitBufferTest {
diff --git a/src/test/java/org/traccar/helper/BitUtilTest.java b/src/test/java/org/traccar/helper/BitUtilTest.java
index 90431bf55..803c327bc 100644
--- a/src/test/java/org/traccar/helper/BitUtilTest.java
+++ b/src/test/java/org/traccar/helper/BitUtilTest.java
@@ -1,10 +1,10 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class BitUtilTest {
diff --git a/src/test/java/org/traccar/helper/BufferUtilTest.java b/src/test/java/org/traccar/helper/BufferUtilTest.java
index b539b5b28..707e419ec 100644
--- a/src/test/java/org/traccar/helper/BufferUtilTest.java
+++ b/src/test/java/org/traccar/helper/BufferUtilTest.java
@@ -2,15 +2,21 @@ package org.traccar.helper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class BufferUtilTest {
@Test
+ public void testReadSignedMagnitudeInt() {
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex("80000001"));
+ assertEquals(-1, BufferUtil.readSignedMagnitudeInt(buf));
+ }
+
+ @Test
public void test1() {
ByteBuf buf = Unpooled.copiedBuffer("abcdef", StandardCharsets.US_ASCII);
assertEquals(2, BufferUtil.indexOf("cd", buf));
diff --git a/src/test/java/org/traccar/helper/ChecksumTest.java b/src/test/java/org/traccar/helper/ChecksumTest.java
index 248f4dcae..51f62aba0 100644
--- a/src/test/java/org/traccar/helper/ChecksumTest.java
+++ b/src/test/java/org/traccar/helper/ChecksumTest.java
@@ -2,12 +2,12 @@ package org.traccar.helper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class ChecksumTest {
diff --git a/src/test/java/org/traccar/helper/DateBuilderTest.java b/src/test/java/org/traccar/helper/DateBuilderTest.java
index b6323cc1d..35797a3ef 100644
--- a/src/test/java/org/traccar/helper/DateBuilderTest.java
+++ b/src/test/java/org/traccar/helper/DateBuilderTest.java
@@ -1,13 +1,13 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateBuilderTest {
diff --git a/src/test/java/org/traccar/helper/DateUtilTest.java b/src/test/java/org/traccar/helper/DateUtilTest.java
index ec42e71ae..b5a4b1eab 100644
--- a/src/test/java/org/traccar/helper/DateUtilTest.java
+++ b/src/test/java/org/traccar/helper/DateUtilTest.java
@@ -1,13 +1,13 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateUtilTest {
diff --git a/src/test/java/org/traccar/helper/DistanceCalculatorTest.java b/src/test/java/org/traccar/helper/DistanceCalculatorTest.java
index a7457b6c4..676fda5ea 100644
--- a/src/test/java/org/traccar/helper/DistanceCalculatorTest.java
+++ b/src/test/java/org/traccar/helper/DistanceCalculatorTest.java
@@ -1,8 +1,8 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class DistanceCalculatorTest {
diff --git a/src/test/java/org/traccar/helper/LogTest.java b/src/test/java/org/traccar/helper/LogTest.java
index ef33c32ba..a264896b5 100644
--- a/src/test/java/org/traccar/helper/LogTest.java
+++ b/src/test/java/org/traccar/helper/LogTest.java
@@ -1,8 +1,8 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class LogTest {
diff --git a/src/test/java/org/traccar/helper/ObdDecoderTest.java b/src/test/java/org/traccar/helper/ObdDecoderTest.java
index d5071bd51..2233ab5b3 100644
--- a/src/test/java/org/traccar/helper/ObdDecoderTest.java
+++ b/src/test/java/org/traccar/helper/ObdDecoderTest.java
@@ -1,8 +1,8 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class ObdDecoderTest {
diff --git a/src/test/java/org/traccar/helper/PatternBuilderTest.java b/src/test/java/org/traccar/helper/PatternBuilderTest.java
index 4c76bc463..a8657a2e7 100644
--- a/src/test/java/org/traccar/helper/PatternBuilderTest.java
+++ b/src/test/java/org/traccar/helper/PatternBuilderTest.java
@@ -1,8 +1,8 @@
package org.traccar.helper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class PatternBuilderTest {
diff --git a/src/test/java/org/traccar/helper/PatternUtilTest.java b/src/test/java/org/traccar/helper/PatternUtilTest.java
index 77660078a..ff8efe773 100644
--- a/src/test/java/org/traccar/helper/PatternUtilTest.java
+++ b/src/test/java/org/traccar/helper/PatternUtilTest.java
@@ -1,13 +1,13 @@
package org.traccar.helper;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class PatternUtilTest {
- @Ignore
+ @Disabled
@Test
public void testCheckPattern() {
diff --git a/src/test/java/org/traccar/helper/ServletHelperTest.java b/src/test/java/org/traccar/helper/ServletHelperTest.java
deleted file mode 100644
index e419b6491..000000000
--- a/src/test/java/org/traccar/helper/ServletHelperTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.traccar.helper;
-
-import org.apache.struts.mock.MockHttpServletRequest;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-
-public class ServletHelperTest {
-
- @Test
- public void testRetrieveRemoteAddressProxyMultiple() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("147.120.1.5");
- request.addHeader("X-FORWARDED-FOR", "231.23.45.65, 10.20.10.33, 10.20.20.34");
-
- assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
- }
-
- @Test
- public void testRetrieveRemoteAddressProxySingle() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("147.120.1.5");
- request.addHeader("X-FORWARDED-FOR", "231.23.45.65");
-
- assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
- }
-
- @Test
- public void testRetrieveRemoteAddressNoProxy() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("231.23.45.65");
-
- assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
- }
-
- private final static class MockRequest extends MockHttpServletRequest {
-
- private String remoteAddress;
-
- private Map<String, String> headers = new HashMap<>();
-
- public void setRemoteAddress(String remoteAddress) {
- this.remoteAddress = remoteAddress;
- }
-
- public void addHeader(String name, String value) {
- headers.put(name, value);
- }
-
- @Override
- public String getHeader(String name) {
- return headers.get(name);
- }
-
- @Override
- public String getRemoteAddr() {
- return remoteAddress;
- }
-
- }
-
-}
diff --git a/src/test/java/org/traccar/helper/WebHelperTest.java b/src/test/java/org/traccar/helper/WebHelperTest.java
new file mode 100644
index 000000000..da18be11e
--- /dev/null
+++ b/src/test/java/org/traccar/helper/WebHelperTest.java
@@ -0,0 +1,39 @@
+package org.traccar.helper;
+
+import org.junit.jupiter.api.Test;
+
+import jakarta.servlet.http.HttpServletRequest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class WebHelperTest {
+
+ @Test
+ public void testRetrieveRemoteAddressProxyMultiple() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65, 10.20.10.33, 10.20.20.34");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+ @Test
+ public void testRetrieveRemoteAddressProxySingle() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+ @Test
+ public void testRetrieveRemoteAddressNoProxy() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("231.23.45.65");
+
+ assertEquals("231.23.45.65", WebHelper.retrieveRemoteAddress(request));
+ }
+
+}