blob: 28220b71119db50ba92ff618377441a6a91bd88a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package org.traccar.helper;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.traccar.model.Data;
import org.traccar.model.Position;
public class DecoderVerifier {
private static void verifyPosition(Position position) {
assertNotNull(position.getDeviceId());
assertNotNull(position.getFixTime());
assertTrue(position.getFixTime().after(new Date(946684800000L))); // 2000 year
assertTrue(position.getFixTime().getTime() < System.currentTimeMillis() + 3600000); // 1 hour from now
assertNotNull(position.getValid());
assertNotNull(position.getLatitude());
assertTrue(position.getLatitude() >= -90);
assertTrue(position.getLatitude() <= 90);
assertNotNull(position.getLongitude());
assertTrue(position.getLongitude() >= -180);
assertTrue(position.getLongitude() <= 180);
assertNotNull(position.getAltitude());
assertTrue(position.getAltitude() >= -12262);
assertTrue(position.getAltitude() <= 18000);
assertNotNull(position.getSpeed());
assertTrue(position.getSpeed() >= 0);
assertTrue(position.getSpeed() <= 869);
assertNotNull(position.getCourse());
assertTrue(position.getCourse() >= 0);
assertTrue(position.getCourse() <= 360);
assertNotNull(position.getAttributes());
}
private static void verifyData(Data data) {
assertNotNull(data.getDeviceId());
assertNotNull(data.getAttributes());
}
public static void verify(Object object) {
assertNotNull(object);
if (object instanceof Position) {
verifyPosition((Position) object);
} else if (object instanceof Data) {
verifyData((Data) object);
} else if (object instanceof List) {
List positions = (List) object;
assertFalse(positions.isEmpty());
for (Object item : positions) {
if (item instanceof Position) {
verifyPosition((Position) item);
} else if (item instanceof Data) {
verifyData((Data) item);
}
}
}
}
}
|