Skip to content

Commit 0d13e56

Browse files
committed
Added tests for consecutive calls to putAll.
1 parent f1d354c commit 0d13e56

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/test/java/org/json/junit/JSONArrayTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,44 @@ public void verifyConstructor() {
225225
expected.similar(jaObj));
226226
}
227227

228+
/**
229+
* Tests consecutive calls to putAll with array and collection.
230+
*/
231+
@Test
232+
public void verifyPutAll() {
233+
final JSONArray jsonArray = new JSONArray();
234+
235+
// array
236+
int[] myInts = { 1, 2, 3, 4, 5 };
237+
jsonArray.putAll(myInts);
238+
239+
assertEquals("int arrays lengths should be equal",
240+
jsonArray.length(),
241+
myInts.length);
242+
243+
for (int i = 0; i < myInts.length; i++) {
244+
assertEquals("int arrays elements should be equal",
245+
myInts[i],
246+
jsonArray.getInt(i));
247+
}
248+
249+
// collection
250+
List<String> myList = Arrays.asList("one", "two", "three", "four", "five");
251+
jsonArray.putAll(myList);
252+
253+
int len = myInts.length + myList.size();
254+
255+
assertEquals("arrays lengths should be equal",
256+
jsonArray.length(),
257+
len);
258+
259+
for (int i = 0; i < myList.size(); i++) {
260+
assertEquals("collection elements should be equal",
261+
myList.get(i),
262+
jsonArray.getString(myInts.length + i));
263+
}
264+
}
265+
228266
/**
229267
* Verifies that the put Collection has backwards compatibility with RAW types pre-java5.
230268
*/

0 commit comments

Comments
 (0)