forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestArray.java
More file actions
72 lines (59 loc) · 2.16 KB
/
TestArray.java
File metadata and controls
72 lines (59 loc) · 2.16 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
package com.jsoniter.output;
import com.jsoniter.spi.TypeLiteral;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TestArray extends TestCase {
static {
// JsonStream.setMode(EncodingMode.REFLECTION_MODE);
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public void test_gen_array() throws IOException {
stream.writeVal(new String[] {"hello", "world"});
stream.close();
assertEquals("['hello','world']".replace('\'', '"'), baos.toString());
}
public void test_collection() throws IOException {
ArrayList list = new ArrayList();
list.add("hello");
list.add("world");
stream.writeVal(new TypeLiteral<List<String>>(){}, list);
stream.close();
assertEquals("['hello','world']".replace('\'', '"'), baos.toString());
}
public void test_collection_without_type() throws IOException {
ArrayList list = new ArrayList();
list.add("hello");
list.add("world");
stream.writeVal(list);
stream.close();
assertEquals("['hello','world']".replace('\'', '"'), baos.toString());
}
public void test_empty_array() throws IOException {
stream.writeVal(new String[0]);
stream.close();
assertEquals("[]".replace('\'', '"'), baos.toString());
}
public void test_null_array() throws IOException {
stream.writeVal(new TypeLiteral<String[]>(){}, null);
stream.close();
assertEquals("null".replace('\'', '"'), baos.toString());
}
public void test_empty_collection() throws IOException {
stream.writeVal(new ArrayList());
stream.close();
assertEquals("[]".replace('\'', '"'), baos.toString());
}
public void test_null_collection() throws IOException {
stream.writeVal(new TypeLiteral<ArrayList>(){}, null);
stream.close();
assertEquals("null".replace('\'', '"'), baos.toString());
}
}