forked from segmentio/analytics-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializationTest.java
More file actions
74 lines (49 loc) · 1.4 KB
/
Copy pathSerializationTest.java
File metadata and controls
74 lines (49 loc) · 1.4 KB
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
package com.github.segmentio;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;
import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.github.segmentio.models.Props;
import com.github.segmentio.utils.GSONUtils;
import com.google.gson.Gson;
public class SerializationTest {
private static Gson gson;
@BeforeClass
public static void setup() {
gson = GSONUtils.BUILDER.create();
}
@Test
public void testArrays() {
String[] stringArray = { "One", "Two" };
Props props = new Props(
"string", "Some string",
"stringArray", stringArray
);
String json = gson.toJson(props);
Assert.assertEquals("{\"stringArray\":[\"One\",\"Two\"],\"string\":\"Some string\"}", json);
}
@Test
public void testLists() {
List<String> list = new LinkedList<String>();
list.add("One");
list.add("Two");
Props props = new Props(
"string", "Some string",
"stringList", list
);
String json = gson.toJson(props);
Assert.assertEquals("{\"stringList\":[\"One\",\"Two\"],\"string\":\"Some string\"}", json);
}
@Test
public void testBigDecimal() {
BigDecimal decimal = BigDecimal.valueOf(1.202);
Props props = new Props(
"string", "Some string",
"decimal", decimal
);
String json = gson.toJson(props);
Assert.assertEquals("{\"decimal\":1.202,\"string\":\"Some string\"}", json);
}
}