mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Added UnitTests
(I hope they works :c)
This commit is contained in:
parent
c7130d577a
commit
efad1d73a7
@ -1254,4 +1254,19 @@ public class JSONArrayTest {
|
|||||||
assertEquals("index " + i + " are equal", a1.get(i), a2.get(i));
|
assertEquals("index " + i + " are equal", a1.get(i), a2.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if calling JSONArray clear() method actually makes the JSONArray empty
|
||||||
|
*/
|
||||||
|
@Test(expected = JSONException.class)
|
||||||
|
public void jsonArrayClearMethodTest() {
|
||||||
|
//Adds random stuff to the JSONArray
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
jsonArray.put(123);
|
||||||
|
jsonArray.put("456");
|
||||||
|
jsonArray.put(new JSONArray());
|
||||||
|
jsonArray.clear(); //Clears the JSONArray
|
||||||
|
assertTrue("expected jsonArray.length() == 0", jsonArray.length() == 0); //Check if its length is 0
|
||||||
|
jsonArray.getInt(0); //Should throws org.json.JSONException: JSONArray[0] not found
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3215,4 +3215,19 @@ public class JSONObjectTest {
|
|||||||
assertNotNull("'empty_json_array' should be an array", jsonObject.getJSONArray("empty_json_array"));
|
assertNotNull("'empty_json_array' should be an array", jsonObject.getJSONArray("empty_json_array"));
|
||||||
assertEquals("'empty_json_array' should have a length of 0", 0, jsonObject.getJSONArray("empty_json_array").length());
|
assertEquals("'empty_json_array' should have a length of 0", 0, jsonObject.getJSONArray("empty_json_array").length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if calling JSONObject clear() method actually makes the JSONObject empty
|
||||||
|
*/
|
||||||
|
@Test(expected = JSONException.class)
|
||||||
|
public void jsonObjectClearMethodTest() {
|
||||||
|
//Adds random stuff to the JSONObject
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("key1", 123);
|
||||||
|
jsonObject.put("key2", "456");
|
||||||
|
jsonObject.put("key3", new JSONObject());
|
||||||
|
jsonObject.clear(); //Clears the JSONObject
|
||||||
|
assertTrue("expected jsonObject.length() == 0", jsonObject.length() == 0); //Check if its length is 0
|
||||||
|
jsonObject.getInt("key1"); //Should throws org.json.JSONException: JSONObject["asd"] not found
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user