FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JSON-java/tests/TestCDL.java at master · zerokilobytes/JSON-java · GitHub
zerokilobytes
/
JSON-java
Public
forked from
stleary/JSON-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JSON-java
/
tests
/
TestCDL.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
351 lines (319 loc) · 8.88 KB
Breadcrumbs
JSON-java
/
tests
/
TestCDL.java
Copy path
File metadata and controls
351 lines (319 loc) · 8.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
* File: TestCDL.java Author: JSON.org
*/
package
org
.
json
.
tests
;
import
org
.
json
.
CDL
;
import
org
.
json
.
JSONArray
;
import
org
.
json
.
JSONException
;
import
org
.
json
.
JSONObject
;
import
org
.
junit
.
Before
;
import
junit
.
framework
.
TestCase
;
/**
* The Class TestCDL.
*/
public
class
TestCDL
extends
TestCase
{
/** The string. */
private
String
string
;
/** The jsonarray. */
private
JSONArray
jsonarray
;
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
@
Before
@
Override
public
void
setUp
()
{
//@formatter:off
string
=
"abc,test,123
\n
"
+
"gg,hh,jj
\n
"
+
"aa,bb,cc
\n
"
;
//@formatter:on
try
{
jsonarray
=
new
JSONArray
();
JSONObject
jo
=
new
JSONObject
();
JSONObject
jo2
=
new
JSONObject
();
jo
.
put
(
"abc"
,
"gg"
);
jo
.
put
(
"test"
,
"hh"
);
jo
.
put
(
"123"
,
"jj"
);
jo2
.
put
(
"abc"
,
"aa"
);
jo2
.
put
(
"test"
,
"bb"
);
jo2
.
put
(
"123"
,
"cc"
);
jsonarray
.
put
(
jo
);
jsonarray
.
put
(
jo2
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method.
*/
public
void
testToJsonArray
()
{
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using No names.
*/
public
static
void
testToJsonArray_NoNames
()
{
try
{
assertEquals
(
null
,
CDL
.
toJSONArray
(
new
JSONArray
(),
"abc,123"
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using Null names.
*/
public
static
void
testToJsonArray_NullNames
()
{
try
{
assertEquals
(
null
,
CDL
.
toJSONArray
(
null
,
"abc,123"
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using No data.
*/
public
static
void
testToJsonArray_NoData
()
{
try
{
assertEquals
(
null
,
CDL
.
toJSONArray
(
"abc,123
\n
"
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using weird data.
*/
public
void
testToJsonArray_WeirdData
()
{
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,
\"
jj
\"
\r
"
+
"aa,
\t
bb,cc"
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using no closing quote.
*/
public
void
testToJsonArray_NoClosingQuote
()
{
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,jj
\r
"
+
"aa,
\"
bb ,cc "
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
fail
(
"Should have thrown Exception"
);
}
catch
(
JSONException
e
)
{
assertEquals
(
"Missing close quote '
\"
'. at 35 [character 12 line 5]"
,
e
.
getMessage
());
}
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,jj
\r
"
+
"aa,
\"
bb ,cc
\n
"
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
fail
(
"Should have thrown Exception"
);
}
catch
(
JSONException
e
)
{
assertEquals
(
"Missing close quote '
\"
'. at 35 [character 0 line 6]"
,
e
.
getMessage
());
}
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,jj
\r
"
+
"aa,
\"
bb ,cc
\r
"
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
fail
(
"Should have thrown Exception"
);
}
catch
(
JSONException
e
)
{
assertEquals
(
"Missing close quote '
\"
'. at 35 [character 12 line 5]"
,
e
.
getMessage
());
}
}
/**
* Tests the toJsonArray method using space after string.
*/
public
void
testToJsonArray_SpaceAfterString
()
{
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,jj
\r
"
+
"aa,
\"
bb
\"
,cc
\r
"
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toJsonArray method using bad character.
*/
public
void
testToJsonArray_BadCharacter
()
{
//@formatter:off
string
=
"abc,test,123
\r
"
+
"gg,hh,jj
\r
"
+
"aa,
\"
bb
\"
?,cc
\r
"
;
//@formatter:on
try
{
assertEquals
(
jsonarray
.
toString
(),
CDL
.
toJSONArray
(
string
)
.
toString
());
fail
(
"Should have thrown Exception"
);
}
catch
(
JSONException
e
)
{
assertEquals
(
"Bad character '?' (63). at 32 [character 9 line 5]"
,
e
.
getMessage
());
}
}
/**
* Tests the toString method.
*/
public
void
testToString
()
{
try
{
assertEquals
(
string
,
CDL
.
toString
(
jsonarray
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toString method using Bad json array.
*/
public
void
testToString_BadJsonArray
()
{
try
{
jsonarray
=
new
JSONArray
();
assertEquals
(
null
,
CDL
.
toString
(
jsonarray
));
jsonarray
.
put
(
"abc"
);
assertEquals
(
""
,
CDL
.
toString
(
jsonarray
,
jsonarray
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toString method using No names.
*/
public
void
testToString_NoNames
()
{
try
{
jsonarray
=
new
JSONArray
();
JSONObject
jo
=
new
JSONObject
();
jsonarray
.
put
(
jo
);
assertEquals
(
null
,
CDL
.
toString
(
jsonarray
));
assertEquals
(
null
,
CDL
.
toString
(
new
JSONArray
(),
jsonarray
));
JSONArray
names
=
new
JSONArray
();
names
.
put
(
""
);
assertEquals
(
"
\n
"
,
CDL
.
toString
(
names
,
jsonarray
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toString method using Null names.
*/
public
void
testToString_NullNames
()
{
try
{
jsonarray
=
new
JSONArray
();
JSONObject
jo
=
new
JSONObject
();
jsonarray
.
put
(
jo
);
assertEquals
(
null
,
CDL
.
toString
(
null
,
jsonarray
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the toString method using Quotes.
*/
public
void
testToString_Quotes
()
{
try
{
jsonarray
=
CDL
.
toJSONArray
(
"Comma delimited list test, '
\"
Strip
\"
Quotes', 'quote, comma', No quotes, 'Single Quotes',
\"
Double Quotes
\"
\n
1,'2',
\"
3
\"
\n
,'It is
\"
good,
\"
',
\"
It works.
\"
\n
\n
"
);
string
=
CDL
.
toString
(
jsonarray
);
assertEquals
(
"
\"
quote, comma
\"
,
\"
StripQuotes
\"
,Comma delimited list test
\n
"
+
"3,2,1
\n
"
+
"It works.,
\"
It is good,
\"
,
\n
"
,
string
);
assertEquals
(
"[
\n
{
\n
\"
quote, comma
\"
:
\"
3
\"
,
\n
\"
\\
\"
Strip
\\
\"
Quotes
\"
:
\"
2
\"
,
\n
\"
Comma delimited list test
\"
:
\"
1
\"
\n
},
\n
{
\n
\"
quote, comma
\"
:
\"
It works.
\"
,
\n
\"
\\
\"
Strip
\\
\"
Quotes
\"
:
\"
It is
\\
\"
good,
\\
\"
\"
,
\n
\"
Comma delimited list test
\"
:
\"
\"
\n
}
\n
]"
,
jsonarray
.
toString
(
1
));
jsonarray
=
CDL
.
toJSONArray
(
string
);
assertEquals
(
"[
\n
{
\n
\"
quote, comma
\"
:
\"
3
\"
,
\n
\"
StripQuotes
\"
:
\"
2
\"
,
\n
\"
Comma delimited list test
\"
:
\"
1
\"
\n
},
\n
{
\n
\"
quote, comma
\"
:
\"
It works.
\"
,
\n
\"
StripQuotes
\"
:
\"
It is good,
\"
,
\n
\"
Comma delimited list test
\"
:
\"
\"
\n
}
\n
]"
,
jsonarray
.
toString
(
1
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Tests the constructor method.
*/
public
static
void
testConstructor
()
{
CDL
cdl
=
new
CDL
();
assertEquals
(
"CDL"
,
cdl
.
getClass
().
getSimpleName
());
}
}
Back
|
FazBrowse Home
|
New Git URL