Skip to content

Commit abe421e

Browse files
committed
clean up code
1 parent 48c872f commit abe421e

File tree

5 files changed

+196
-399
lines changed

5 files changed

+196
-399
lines changed

CookieListTest.java

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ public void emptyStringCookieList() {
7575
public void simpleCookieList() {
7676
String cookieStr = "SID=31d4d96e407aad42";
7777
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
78-
Object doc = Configuration.defaultConfiguration().jsonProvider().
79-
parse(jsonObject.toString());
80-
assertTrue("Expected 1 top level item",
81-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 1);
82-
assertTrue("expected 31d4d96e407aad42",
83-
"31d4d96e407aad42".equals(JsonPath.read(doc, "$.SID")));
78+
// validate JSON content
79+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
80+
assertTrue("Expected 1 top level item", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 1);
81+
assertTrue("expected 31d4d96e407aad42", "31d4d96e407aad42".equals(JsonPath.read(doc, "$.SID")));
8482
}
8583

8684
/**
@@ -90,12 +88,10 @@ public void simpleCookieList() {
9088
public void simpleCookieListWithDelimiter() {
9189
String cookieStr = "SID=31d4d96e407aad42;";
9290
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
93-
Object doc = Configuration.defaultConfiguration().jsonProvider().
94-
parse(jsonObject.toString());
95-
assertTrue("Expected 1 top level item",
96-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 1);
97-
assertTrue("expected 31d4d96e407aad42",
98-
"31d4d96e407aad42".equals(JsonPath.read(doc, "$.SID")));
91+
// validate JSON content
92+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
93+
assertTrue("Expected 1 top level item", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 1);
94+
assertTrue("expected 31d4d96e407aad42", "31d4d96e407aad42".equals(JsonPath.read(doc, "$.SID")));
9995
}
10096

10197
/**
@@ -112,22 +108,15 @@ public void multiPartCookieList() {
112108
"name5=myCookieValue5;"+
113109
" name6=myCookieValue6;";
114110
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
115-
Object doc = Configuration.defaultConfiguration().jsonProvider().
116-
parse(jsonObject.toString());
117-
assertTrue("Expected 6 top level items",
118-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
119-
assertTrue("expected myCookieValue1",
120-
"myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
121-
assertTrue("expected myCookieValue2",
122-
"myCookieValue2".equals(JsonPath.read(doc, "$.name2")));
123-
assertTrue("expected myCookieValue3",
124-
"myCookieValue3".equals(JsonPath.read(doc, "$.name3")));
125-
assertTrue("expected myCookieValue4",
126-
"myCookieValue4".equals(JsonPath.read(doc, "$.name4")));
127-
assertTrue("expected myCookieValue5",
128-
"myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
129-
assertTrue("expected myCookieValue6",
130-
"myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
111+
// validate JSON content
112+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
113+
assertTrue("Expected 6 top level items", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
114+
assertTrue("expected myCookieValue1", "myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
115+
assertTrue("expected myCookieValue2", "myCookieValue2".equals(JsonPath.read(doc, "$.name2")));
116+
assertTrue("expected myCookieValue3", "myCookieValue3".equals(JsonPath.read(doc, "$.name3")));
117+
assertTrue("expected myCookieValue4", "myCookieValue4".equals(JsonPath.read(doc, "$.name4")));
118+
assertTrue("expected myCookieValue5", "myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
119+
assertTrue("expected myCookieValue6", "myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
131120
}
132121

133122
/**
@@ -154,22 +143,15 @@ public void convertCookieListToString() {
154143
"name5=myCookieValue5;"+
155144
" name6=myCookieValue6;";
156145
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
157-
Object doc = Configuration.defaultConfiguration().jsonProvider().
158-
parse(jsonObject.toString());
159-
assertTrue("Expected 6 top level items",
160-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
161-
assertTrue("expected myCookieValue1",
162-
"myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
163-
assertTrue("expected myCookieValue2",
164-
"myCookieValue2".equals(JsonPath.read(doc, "$.name2")));
165-
assertTrue("expected myCookieValue3",
166-
"myCookieValue3".equals(JsonPath.read(doc, "$.name3")));
167-
assertTrue("expected myCookieValue4",
168-
"myCookieValue4".equals(JsonPath.read(doc, "$.name4")));
169-
assertTrue("expected myCookieValue5",
170-
"myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
171-
assertTrue("expected myCookieValue6",
172-
"myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
146+
// validate JSON content
147+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
148+
assertTrue("Expected 6 top level items", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
149+
assertTrue("expected myCookieValue1", "myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
150+
assertTrue("expected myCookieValue2", "myCookieValue2".equals(JsonPath.read(doc, "$.name2")));
151+
assertTrue("expected myCookieValue3", "myCookieValue3".equals(JsonPath.read(doc, "$.name3")));
152+
assertTrue("expected myCookieValue4", "myCookieValue4".equals(JsonPath.read(doc, "$.name4")));
153+
assertTrue("expected myCookieValue5", "myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
154+
assertTrue("expected myCookieValue6", "myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
173155
}
174156

175157
/**
@@ -186,21 +168,14 @@ public void convertEncodedCookieListToString() {
186168
"name5=myCookieValue5;"+
187169
" name6=myCookieValue6;";
188170
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
189-
Object doc = Configuration.defaultConfiguration().jsonProvider().
190-
parse(jsonObject.toString());
191-
assertTrue("Expected 6 top level items",
192-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
193-
assertTrue("expected myCookieValue1",
194-
"myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
195-
assertTrue("expected my Cookie Value 2",
196-
"my Cookie Value 2".equals(JsonPath.read(doc, "$.name2")));
197-
assertTrue("expected my+Cookie&Value;3=",
198-
"my+Cookie&Value;3=".equals(JsonPath.read(doc, "$.name3")));
199-
assertTrue("expected my%CookieValue4",
200-
"my%CookieValue4".equals(JsonPath.read(doc, "$.name4")));
201-
assertTrue("expected my%CookieValue5",
202-
"myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
203-
assertTrue("expected myCookieValue6",
204-
"myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
171+
// validate JSON content
172+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
173+
assertTrue("Expected 6 top level items", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 6);
174+
assertTrue("expected myCookieValue1", "myCookieValue1".equals(JsonPath.read(doc, "$.name1")));
175+
assertTrue("expected my Cookie Value 2", "my Cookie Value 2".equals(JsonPath.read(doc, "$.name2")));
176+
assertTrue("expected my+Cookie&Value;3=", "my+Cookie&Value;3=".equals(JsonPath.read(doc, "$.name3")));
177+
assertTrue("expected my%CookieValue4", "my%CookieValue4".equals(JsonPath.read(doc, "$.name4")));
178+
assertTrue("expected my%CookieValue5", "myCookieValue5".equals(JsonPath.read(doc, "$.name5")));
179+
assertTrue("expected myCookieValue6", "myCookieValue6".equals(JsonPath.read(doc, "$.name6")));
205180
}
206181
}

EnumTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public void jsonObjectFromEnum() {
3535
// validate JSON content
3636
Object doc = Configuration.defaultConfiguration().jsonProvider()
3737
.parse(jsonObject.toString());
38-
assertTrue("expecting 2 items in top level object",
39-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 2);
38+
assertTrue("expecting 2 items in top level object", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 2);
4039
assertTrue("expecting val 2", "val 2".equals(JsonPath.read(doc, "$.value")));
4140
assertTrue("expecting 2", Integer.valueOf(2).equals(JsonPath.read(doc, "$.intVal")));
4241

@@ -50,14 +49,10 @@ public void jsonObjectFromEnum() {
5049
jsonObject = new JSONObject(myEnumClass);
5150

5251
// validate JSON content
53-
doc = Configuration.defaultConfiguration().jsonProvider()
54-
.parse(jsonObject.toString());
55-
assertTrue("expecting 2 items in top level object",
56-
((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 2);
57-
assertTrue("expecting 2 items in myEnumField object",
58-
((Map<?,?>)(JsonPath.read(doc, "$.myEnumField"))).size() == 2);
59-
assertTrue("expecting 0 items in myEnum object",
60-
((Map<?,?>)(JsonPath.read(doc, "$.myEnum"))).size() == 0);
52+
doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
53+
assertTrue("expecting 2 items in top level object", ((Map<?,?>)(JsonPath.read(doc, "$"))).size() == 2);
54+
assertTrue("expecting 2 items in myEnumField object", ((Map<?,?>)(JsonPath.read(doc, "$.myEnumField"))).size() == 2);
55+
assertTrue("expecting 0 items in myEnum object", ((Map<?,?>)(JsonPath.read(doc, "$.myEnum"))).size() == 0);
6156
assertTrue("expecting 3", Integer.valueOf(3).equals(JsonPath.read(doc, "$.myEnumField.intVal")));
6257
assertTrue("expecting val 3", "val 3".equals(JsonPath.read(doc, "$.myEnumField.value")));
6358
}

JSONArrayTest.java

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,8 @@ public void join() {
314314
/**
315315
* Don't need to remake the JSONArray to perform the parsing
316316
*/
317-
Object doc = Configuration.defaultConfiguration().jsonProvider()
318-
.parse("["+joinStr+"]");
319-
List<?> docList = JsonPath.read(doc, "$");
320-
assertTrue("expected 13 items in top level object", docList.size() == 13);
317+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse("["+joinStr+"]");
318+
assertTrue("expected 13 items in top level object", ((List<?>)(JsonPath.read(doc, "$"))).size() == 13);
321319
assertTrue("expected true", Boolean.TRUE.equals(JsonPath.read(doc, "$[0]")));
322320
assertTrue("expected false", Boolean.FALSE.equals(JsonPath.read(doc, "$[1]")));
323321
assertTrue("expected \"true\"", "true".equals(JsonPath.read(doc, "$[2]")));
@@ -327,11 +325,9 @@ public void join() {
327325
assertTrue("expected \"23.45\"", "23.45".equals(JsonPath.read(doc, "$[6]")));
328326
assertTrue("expected 42", Integer.valueOf(42).equals(JsonPath.read(doc, "$[7]")));
329327
assertTrue("expected \"43\"", "43".equals(JsonPath.read(doc, "$[8]")));
330-
docList = JsonPath.read(doc, "$[9]");
331-
assertTrue("expected 1 array item", docList.size() == 1);
328+
assertTrue("expected 1 item in [9]", ((List<?>)(JsonPath.read(doc, "$[9]"))).size() == 1);
332329
assertTrue("expected world", "world".equals(JsonPath.read(doc, "$[9][0]")));
333-
Map<?,?> docMap = JsonPath.read(doc, "$[10]");
334-
assertTrue("expected 4 object items", docMap.size() == 4);
330+
assertTrue("expected 4 items in [10]", ((Map<?,?>)(JsonPath.read(doc, "$[10]"))).size() == 4);
335331
assertTrue("expected value1", "value1".equals(JsonPath.read(doc, "$[10].key1")));
336332
assertTrue("expected value2", "value2".equals(JsonPath.read(doc, "$[10].key2")));
337333
assertTrue("expected value3", "value3".equals(JsonPath.read(doc, "$[10].key3")));
@@ -463,30 +459,24 @@ public void put() {
463459
jsonArray.put(collection);
464460

465461
// validate JSON
466-
Object doc = Configuration.defaultConfiguration().jsonProvider()
467-
.parse(jsonArray.toString());
468-
List<?> docList = JsonPath.read(doc, "$");
469-
assertTrue("expected 10 items in top level object", docList.size() == 10);
462+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString());
463+
assertTrue("expected 10 top level items", ((List<?>)(JsonPath.read(doc, "$"))).size() == 10);
470464
assertTrue("expected true", Boolean.TRUE.equals(JsonPath.read(doc, "$[0]")));
471465
assertTrue("expected false", Boolean.FALSE.equals(JsonPath.read(doc, "$[1]")));
472-
docList = JsonPath.read(doc, "$[2]");
473-
assertTrue("expected 2 items in array", docList.size() == 2);
466+
assertTrue("expected 2 items in [2]", ((List<?>)(JsonPath.read(doc, "$[2]"))).size() == 2);
474467
assertTrue("expected hello", "hello".equals(JsonPath.read(doc, "$[2][0]")));
475468
assertTrue("expected world", "world".equals(JsonPath.read(doc, "$[2][1]")));
476469
assertTrue("expected 2.5", Double.valueOf(2.5).equals(JsonPath.read(doc, "$[3]")));
477470
assertTrue("expected 1", Integer.valueOf(1).equals(JsonPath.read(doc, "$[4]")));
478471
assertTrue("expected 45", Integer.valueOf(45).equals(JsonPath.read(doc, "$[5]")));
479472
assertTrue("expected objectPut", "objectPut".equals(JsonPath.read(doc, "$[6]")));
480-
Map<?,?> docMap = JsonPath.read(doc, "$[7]");
481-
assertTrue("expected 3 items in object", docMap.size() == 3);
473+
assertTrue("expected 3 items in [7]", ((Map<?,?>)(JsonPath.read(doc, "$[7]"))).size() == 3);
482474
assertTrue("expected val10", "val10".equals(JsonPath.read(doc, "$[7].key10")));
483475
assertTrue("expected val20", "val20".equals(JsonPath.read(doc, "$[7].key20")));
484476
assertTrue("expected val30", "val30".equals(JsonPath.read(doc, "$[7].key30")));
485-
docMap = JsonPath.read(doc, "$[8]");
486-
assertTrue("expected 1 item in object", docMap.size() == 1);
477+
assertTrue("expected 1 item in [8]", ((Map<?,?>)(JsonPath.read(doc, "$[8]"))).size() == 1);
487478
assertTrue("expected v1", "v1".equals(JsonPath.read(doc, "$[8].k1")));
488-
docList = JsonPath.read(doc, "$[9]");
489-
assertTrue("expected 2 items in array", docList.size() == 2);
479+
assertTrue("expected 2 items in [9]", ((List<?>)(JsonPath.read(doc, "$[9]"))).size() == 2);
490480
assertTrue("expected 1", Integer.valueOf(1).equals(JsonPath.read(doc, "$[9][0]")));
491481
assertTrue("expected 2", Integer.valueOf(2).equals(JsonPath.read(doc, "$[9][1]")));
492482
}
@@ -546,32 +536,26 @@ public void putIndex() {
546536
} catch(Exception ignored) {}
547537

548538
// validate JSON
549-
Object doc = Configuration.defaultConfiguration().jsonProvider()
550-
.parse(jsonArray.toString());
551-
List<?> docList = JsonPath.read(doc, "$");
552-
assertTrue("expected 11 items in top level object", docList.size() == 11);
539+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString());
540+
assertTrue("expected 11 top level items", ((List<?>)(JsonPath.read(doc, "$"))).size() == 11);
553541
assertTrue("expected true", Boolean.TRUE.equals(JsonPath.read(doc, "$[0]")));
554542
assertTrue("expected false", Boolean.FALSE.equals(JsonPath.read(doc, "$[1]")));
555-
docList = JsonPath.read(doc, "$[2]");
556-
assertTrue("expected 2 items in array", docList.size() == 2);
543+
assertTrue("expected 2 items in [2]", ((List<?>)(JsonPath.read(doc, "$[2]"))).size() == 2);
557544
assertTrue("expected hello", "hello".equals(JsonPath.read(doc, "$[2][0]")));
558545
assertTrue("expected world", "world".equals(JsonPath.read(doc, "$[2][1]")));
559546
assertTrue("expected 2.5", Double.valueOf(2.5).equals(JsonPath.read(doc, "$[3]")));
560547
assertTrue("expected 1", Integer.valueOf(1).equals(JsonPath.read(doc, "$[4]")));
561548
assertTrue("expected 45", Integer.valueOf(45).equals(JsonPath.read(doc, "$[5]")));
562549
assertTrue("expected objectPut", "objectPut".equals(JsonPath.read(doc, "$[6]")));
563550
assertTrue("expected null", null == JsonPath.read(doc, "$[7]"));
564-
Map<?,?> docMap = JsonPath.read(doc, "$[8]");
565-
assertTrue("expected 3 items in object", docMap.size() == 3);
551+
assertTrue("expected 3 items in [8]", ((Map<?,?>)(JsonPath.read(doc, "$[8]"))).size() == 3);
566552
assertTrue("expected val10", "val10".equals(JsonPath.read(doc, "$[8].key10")));
567553
assertTrue("expected val20", "val20".equals(JsonPath.read(doc, "$[8].key20")));
568554
assertTrue("expected val30", "val30".equals(JsonPath.read(doc, "$[8].key30")));
569-
docList = JsonPath.read(doc, "$[9]");
570-
assertTrue("expected 2 items in array", docList.size() == 2);
555+
assertTrue("expected 2 items in [9]", ((List<?>)(JsonPath.read(doc, "$[9]"))).size() == 2);
571556
assertTrue("expected 1", Integer.valueOf(1).equals(JsonPath.read(doc, "$[9][0]")));
572557
assertTrue("expected 2", Integer.valueOf(2).equals(JsonPath.read(doc, "$[9][1]")));
573-
docMap = JsonPath.read(doc, "$[10]");
574-
assertTrue("expected 1 item in object", docMap.size() == 1);
558+
assertTrue("expected 1 item in [10]", ((Map<?,?>)(JsonPath.read(doc, "$[10]"))).size() == 1);
575559
assertTrue("expected v1", "v1".equals(JsonPath.read(doc, "$[10].k1")));
576560
}
577561

@@ -651,10 +635,8 @@ public void objectArrayVsIsArray() {
651635
JSONArray jsonArray = new JSONArray(myObject);
652636

653637
// validate JSON
654-
Object doc = Configuration.defaultConfiguration().jsonProvider()
655-
.parse(jsonArray.toString());
656-
List<?> docList = JsonPath.read(doc, "$");
657-
assertTrue("expected 7 items in top level object", docList.size() == 7);
638+
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString());
639+
assertTrue("expected 7 top level items", ((List<?>)(JsonPath.read(doc, "$"))).size() == 7);
658640
assertTrue("expected 1", Integer.valueOf(1).equals(JsonPath.read(doc, "$[0]")));
659641
assertTrue("expected 2", Integer.valueOf(2).equals(JsonPath.read(doc, "$[1]")));
660642
assertTrue("expected 3", Integer.valueOf(3).equals(JsonPath.read(doc, "$[2]")));

0 commit comments

Comments
 (0)