From 0d13e5606456f34d9b89e0756aad2bd55ea5b44d Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 21 Jul 2020 23:09:28 -0700 Subject: [PATCH] Added tests for consecutive calls to putAll. --- .../java/org/json/junit/JSONArrayTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java index eda3c06bd..f11b953e5 100644 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ b/src/test/java/org/json/junit/JSONArrayTest.java @@ -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 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. */