16
16
17
17
package com .google .gson .graph ;
18
18
19
- import com . google . gson . Gson ;
20
- import com . google . gson . GsonBuilder ;
21
- import com . google . gson . reflect . TypeToken ;
19
+ import static org . junit . Assert . assertEquals ;
20
+ import static org . junit . Assert . assertSame ;
21
+
22
22
import java .lang .reflect .Type ;
23
23
import java .util .ArrayList ;
24
24
import java .util .Collections ;
25
25
import java .util .List ;
26
- import junit .framework .TestCase ;
27
26
28
- public final class GraphAdapterBuilderTest extends TestCase {
27
+ import org .junit .Test ;
28
+
29
+ import com .google .gson .Gson ;
30
+ import com .google .gson .GsonBuilder ;
31
+ import com .google .gson .reflect .TypeToken ;
32
+
33
+ public final class GraphAdapterBuilderTest {
34
+ @ Test
29
35
public void testSerialization () {
30
36
Roshambo rock = new Roshambo ("ROCK" );
31
37
Roshambo scissors = new Roshambo ("SCISSORS" );
@@ -46,6 +52,7 @@ public void testSerialization() {
46
52
gson .toJson (rock ).replace ('"' , '\'' ));
47
53
}
48
54
55
+ @ Test
49
56
public void testDeserialization () {
50
57
String json = "{'0x1':{'name':'ROCK','beats':'0x2'}," +
51
58
"'0x2':{'name':'SCISSORS','beats':'0x3'}," +
@@ -66,6 +73,7 @@ public void testDeserialization() {
66
73
assertSame (rock , paper .beats );
67
74
}
68
75
76
+ @ Test
69
77
public void testSerializationDirectSelfReference () {
70
78
Roshambo suicide = new Roshambo ("SUICIDE" );
71
79
suicide .beats = suicide ;
@@ -87,6 +95,7 @@ public void testSerializationDirectSelfReference() {
87
95
// gson.toJson(suicide).replace('"', '\''));
88
96
}
89
97
98
+ @ Test
90
99
public void testDeserializationDirectSelfReference () {
91
100
String json = "{'0x1':{'name':'SUICIDE','beats':'0x1'}}" ;
92
101
@@ -101,6 +110,7 @@ public void testDeserializationDirectSelfReference() {
101
110
assertSame (suicide , suicide .beats );
102
111
}
103
112
113
+ @ Test
104
114
public void testSerializeListOfLists () {
105
115
Type listOfListsType = new TypeToken <List <List <?>>>() {}.getType ();
106
116
Type listOfAnyType = new TypeToken <List <?>>() {}.getType ();
@@ -120,6 +130,7 @@ public void testSerializeListOfLists() {
120
130
assertEquals ("{'0x1':['0x1','0x2'],'0x2':[]}" , json .replace ('"' , '\'' ));
121
131
}
122
132
133
+ @ Test
123
134
public void testDeserializeListOfLists () {
124
135
Type listOfAnyType = new TypeToken <List <?>>() {}.getType ();
125
136
Type listOfListsType = new TypeToken <List <List <?>>>() {}.getType ();
@@ -137,6 +148,7 @@ public void testDeserializeListOfLists() {
137
148
assertEquals (Collections .emptyList (), listOfLists .get (1 ));
138
149
}
139
150
151
+ @ Test
140
152
public void testSerializationWithMultipleTypes () {
141
153
Company google = new Company ("Google" );
142
154
new Employee ("Jesse" , google );
@@ -155,6 +167,7 @@ public void testSerializationWithMultipleTypes() {
155
167
gson .toJson (google ).replace ('"' , '\'' ));
156
168
}
157
169
170
+ @ Test
158
171
public void testDeserializationWithMultipleTypes () {
159
172
GsonBuilder gsonBuilder = new GsonBuilder ();
160
173
new GraphAdapterBuilder ()
0 commit comments