forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONAssert.java
More file actions
37 lines (28 loc) · 1.04 KB
/
JSONAssert.java
File metadata and controls
37 lines (28 loc) · 1.04 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
package com.pubnub.api.matchers;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import static org.junit.Assert.*;
public class JSONAssert {
public static void assertJSONArrayHasNo(String item, JSONArray jArray) {
assertFalse("JSONArray should not contain item \"" + item + "\"", listData(jArray).contains(item));
}
public static void assertJSONArrayHas(String item, JSONArray jArray) {
assertTrue("JSONArray should contain item \"" + item + "\"", listData(jArray).contains(item));
}
private static ArrayList listData(JSONArray jArray) {
ArrayList<String> listData = new ArrayList<String>();
if (jArray == null) {
fail("JSON decoding error");
jArray = new JSONArray();
}
for (int i = 0; i < jArray.length(); i++) {
try {
listData.add(jArray.get(i).toString());
} catch (JSONException e) {
fail("JSON decoding error");
}
}
return listData;
}
}