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

Merge pull request #14 from stleary/iterable-JSONArray

test iterable JSONArray
This commit is contained in:
Sean Leary 2015-06-07 10:52:51 -05:00
commit a5b00a5244

View file

@ -2,10 +2,7 @@ package org.json.junit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.json.*; import org.json.*;
import org.junit.Test; import org.junit.Test;
@ -464,4 +461,42 @@ public class JSONArrayTest {
JSONArray expectedJsonArray = new JSONArray(expectedStr); JSONArray expectedJsonArray = new JSONArray(expectedStr);
Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray);
} }
@Test
public void iterator() {
JSONArray jsonArray = new JSONArray(arrayStr);
Iterator<Object> it = jsonArray.iterator();
assertTrue("Array true",
Boolean.TRUE.equals(it.next()));
assertTrue("Array false",
Boolean.FALSE.equals(it.next()));
assertTrue("Array string true",
"true".equals(it.next()));
assertTrue("Array string false",
"false".equals(it.next()));
assertTrue("Array string",
"hello".equals(it.next()));
assertTrue("Array double",
new Double(23.45e-4).equals(it.next()));
assertTrue("Array string double",
new Double(23.45).equals(Double.parseDouble((String)it.next())));
assertTrue("Array value int",
new Integer(42).equals(it.next()));
assertTrue("Array value string int",
new Integer(43).equals(Integer.parseInt((String)it.next())));
JSONArray nestedJsonArray = (JSONArray)it.next();
assertTrue("Array value JSONArray", nestedJsonArray != null);
JSONObject nestedJsonObject = (JSONObject)it.next();
assertTrue("Array value JSONObject", nestedJsonObject != null);
assertTrue("Array value long",
new Long(0).equals(((Number) it.next()).longValue()));
assertTrue("Array value string long",
new Long(-1).equals(Long.parseLong((String) it.next())));
assertTrue("should be at end of array", !it.hasNext());
}
} }