forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestReflection.java
More file actions
69 lines (56 loc) · 2.38 KB
/
TestReflection.java
File metadata and controls
69 lines (56 loc) · 2.38 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
package com.jsoniter;
import junit.framework.TestCase;
import org.junit.Assert;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertArrayEquals;
public class TestReflection extends TestCase {
public void test_string() throws IOException {
Jsoniter iter = Jsoniter.parse("'hello'".replace('\'', '"'));
String val = iter.read(String.class);
assertEquals("hello", val);
}
public void test_no_arg_list() throws IOException {
Jsoniter iter = Jsoniter.parse("['hello']".replace('\'', '"'));
Assert.assertArrayEquals(new String[]{"hello"}, iter.read(List.class).toArray(new String[0]));
}
public void test_boolean_array() throws IOException {
Jsoniter iter = Jsoniter.parse("[true, false]");
boolean[] val = iter.read(boolean[].class);
assertArrayEquals(new boolean[]{true, false}, val);
}
public void test_int_array() throws IOException {
Jsoniter iter = Jsoniter.parse("[1,2,3]");
int[] val = iter.read(int[].class);
assertArrayEquals(new int[]{1, 2, 3}, val);
}
public void test_Integer_array() throws IOException {
Jsoniter iter = Jsoniter.parse("[1,2,3]");
Integer[] val = iter.read(Integer[].class);
assertArrayEquals(new Integer[]{1, 2, 3}, val);
}
public void test_float_array() throws IOException {
Jsoniter iter = Jsoniter.parse("[1.1,2,3]");
float[] val = iter.read(float[].class);
assertArrayEquals(new float[]{1.1f, 2f, 3f}, val, 0.01f);
}
public void test_simple_object() throws IOException {
Jsoniter iter = Jsoniter.parse("{'field1': 'hello', 'field2': 'world'}".replace('\'', '"'));
SimpleObject val = iter.read(SimpleObject.class);
assertEquals("hello", val.field1);
assertEquals("world", val.field2);
}
public void test_fields_skipped() throws IOException {
Jsoniter iter = Jsoniter.parse("{'field3': '3', 'field1': 100}".replace('\'', '"'));
ComplexObject val = iter.read(ComplexObject.class);
assertEquals(100, val.field1);
}
public void test_read_object() throws IOException {
Jsoniter iter = Jsoniter.parse("'hello'".replace('\'', '"'));
String val = (String) iter.read(Object.class);
assertEquals("hello", val);
}
}