aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-26 19:05:25 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-26 19:05:25 -0800
commit728e55fc00a4b7b980d6e59f2ce8664859a5c848 (patch)
treeaf71d95acbd58370dd7c0ac4463275513360f610 /test/org/traccar/handler
parent03539bca46f9242ff62db9a6c9ab722ae2bb6a4d (diff)
downloadtraccar-server-728e55fc00a4b7b980d6e59f2ce8664859a5c848.tar.gz
traccar-server-728e55fc00a4b7b980d6e59f2ce8664859a5c848.tar.bz2
traccar-server-728e55fc00a4b7b980d6e59f2ce8664859a5c848.zip
Refactor computed attributes
Diffstat (limited to 'test/org/traccar/handler')
-rw-r--r--test/org/traccar/handler/ComputedAttributesTest.java29
1 files changed, 16 insertions, 13 deletions
diff --git a/test/org/traccar/handler/ComputedAttributesTest.java b/test/org/traccar/handler/ComputedAttributesTest.java
index 8f4f69bcd..a76d8169b 100644
--- a/test/org/traccar/handler/ComputedAttributesTest.java
+++ b/test/org/traccar/handler/ComputedAttributesTest.java
@@ -3,6 +3,7 @@ package org.traccar.handler;
import java.util.Date;
import org.junit.Test;
+import org.traccar.config.Config;
import org.traccar.model.Attribute;
import org.traccar.model.Position;
@@ -12,9 +13,11 @@ public class ComputedAttributesTest {
@Test
public void testComputedAttributes() {
- Position position = new Position();
- ComputedAttributesHandler computedAttributesHandler = new ComputedAttributesHandler();
+
+ ComputedAttributesHandler handler = new ComputedAttributesHandler(new Config(), null, null);
+
Date date = new Date();
+ Position position = new Position();
position.setTime(date);
position.setSpeed(42);
position.setValid(false);
@@ -27,40 +30,40 @@ public class ComputedAttributesTest {
Attribute attribute = new Attribute();
attribute.setExpression("adc1");
- assertEquals(128, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(128, handler.computeAttribute(attribute, position));
attribute.setExpression("!booleanFlag");
- assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(false, handler.computeAttribute(attribute, position));
attribute.setExpression("adc2 * 2 + 50");
- assertEquals(250, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(250, handler.computeAttribute(attribute, position));
attribute.setExpression("(bitFlag & 4) != 0");
- assertEquals(true, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(true, handler.computeAttribute(attribute, position));
attribute.setExpression("if (event == 42) \"lowBattery\"");
- assertEquals("lowBattery", computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals("lowBattery", handler.computeAttribute(attribute, position));
attribute.setExpression("speed > 5 && valid");
- assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(false, handler.computeAttribute(attribute, position));
attribute.setExpression("fixTime");
- assertEquals(date, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(date, handler.computeAttribute(attribute, position));
attribute.setExpression("math:pow(adc1, 2)");
- assertEquals(16384.0, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(16384.0, handler.computeAttribute(attribute, position));
// modification tests
attribute.setExpression("adc1 = 256");
- computedAttributesHandler.computeAttribute(attribute, position);
+ handler.computeAttribute(attribute, position);
assertEquals(128, position.getInteger("adc1"));
attribute.setExpression("result = \"fail\"");
- computedAttributesHandler.computeAttribute(attribute, position);
+ handler.computeAttribute(attribute, position);
assertEquals("success", position.getString("result"));
attribute.setExpression("fixTime = \"2017-10-18 10:00:01\"");
- computedAttributesHandler.computeAttribute(attribute, position);
+ handler.computeAttribute(attribute, position);
assertEquals(date, position.getFixTime());
}