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:
parent
f1d354ce7b
commit
0d13e56064
1 changed files with 38 additions and 0 deletions
|
@ -225,6 +225,44 @@ public class JSONArrayTest {
|
|||
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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue