Skip to content

Commit

Permalink
Added tests for consecutive calls to putAll.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jul 22, 2020
1 parent f1d354c commit 0d13e56
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Expand Up @@ -225,6 +225,44 @@ public void verifyConstructor() {
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.
*/
Expand Down

0 comments on commit 0d13e56

Please sign in to comment.