blob: 8607d49ee9b94c69bbd24620a659d41efa305a45 (
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
|
package org.traccar.web;
import java.io.StringReader;
import java.text.ParseException;
import java.util.Date;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class JsonConverterTest {
@Test
public void primitiveConversion() throws ParseException {
Primitives o = JsonConverter.objectFromJson(new StringReader(
"{" +
"\"boolean\": true, " +
"\"int\": 42, " +
"\"double\": 41.99, " +
"\"string\": \"discworld\", " +
"\"date\":\"2015-07-09T19:02:17.000Z\"" +
"}"),
Primitives.class);
assertEquals(true, o.getBoolean());
assertEquals(42, o.getInt());
assertEquals(41.99, o.getDouble(), 0.001);
assertEquals("discworld", o.getString());
assertEquals(1436468537000L, o.getDate().getTime());
}
public static class Primitives {
private boolean b;
public boolean getBoolean() { return b; }
public void setBoolean(boolean b) { this.b = b; }
private int i;
public int getInt() { return i; }
public void setInt(int i) { this.i = i; }
private long l;
public long getLong() { return l; }
public void setLong(long l) { this.l = l; }
private double d;
public double getDouble() { return d; }
public void setDouble(double d) { this.d = d; }
private String s;
public String getString() { return s; }
public void setString(String s) { this.s = s; }
private Date t;
public Date getDate() { return t; }
public void setDate(Date t) { this.t = t; }
}
}
|