1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Added tests for consecutive calls to putAll.

This commit is contained in:
Erik C. Thauvin 2020-07-21 23:09:28 -07:00
parent f1d354ce7b
commit 0d13e56064

View file

@ -225,6 +225,44 @@ public class JSONArrayTest {
expected.similar(jaObj)); expected.similar(jaObj));
} }
/**
* Tests consecutive calls to putAll with array and collection.
*/
@Test
public void verifyPutAll() {
final JSONArray jsonArray = new JSONArray();
// array
int[] myInts = { 1, 2, 3, 4, 5 };
jsonArray.putAll(myInts);
assertEquals("int arrays lengths should be equal",
jsonArray.length(),
myInts.length);
for (int i = 0; i < myInts.length; i++) {
assertEquals("int arrays elements should be equal",
myInts[i],
jsonArray.getInt(i));
}
// collection
List<String> myList = Arrays.asList("one", "two", "three", "four", "five");
jsonArray.putAll(myList);
int len = myInts.length + myList.size();
assertEquals("arrays lengths should be equal",
jsonArray.length(),
len);
for (int i = 0; i < myList.size(); i++) {
assertEquals("collection elements should be equal",
myList.get(i),
jsonArray.getString(myInts.length + i));
}
}
/** /**
* Verifies that the put Collection has backwards compatibility with RAW types pre-java5. * Verifies that the put Collection has backwards compatibility with RAW types pre-java5.
*/ */